首先让我描述一下我试图用 Python 重现的 Excel 数据透视图。
以下是生成示例数据集的代码:
# The code should work in Python 3.7 and pandas 0.24 or above
import pandas as pd
years = [i for i in range(2015,2021)]
countries = ['US', 'CA', 'JP', 'MX', 'IT']
months = [i for i in range(1,13)]
idx = pd.MultiIndex.from_product([years, countries, months], names=['year', 'country', 'month'])
df = pd.DataFrame(np.random.randn(len(idx), 1),columns=['val'], index=idx).sort_index()
Run Code Online (Sandbox Code Playgroud)
我可以将df.to_clipboard()其粘贴到 Excel 中,如下所示:
然后我可以根据数据插入数据透视图,并以某种方式配置它,以便我可以按年份和国家/地区查看每月线图。该数据透视图是“交互式”的,因为通过“年份”和“国家/地区”下拉控件,我可以以任何我想要的方式方便地过滤数据,例如“显示 JP 的所有年份”或“显示 2020 年的所有国家/地区” ”。
我的问题是:
有没有简单的方法可以在 Python 中创建这样的交互式绘图?我使用 Jupyter Notebook 来处理数据并做了很多这样的探索性研究。我不喜欢每次想要可视化数据时都必须将数据复制到 Excel 中。在Python中,我可以做一些愚蠢的事情,比如df.loc[(2015, 'US'),:].plot() …
我在 jupyter 笔记本中做了一个函数,单元格被删除了。我想知道函数中的代码。我无法使用,undo deleted cell因为它很久以前就被删除了。该函数不会从笔记本内存中删除,因为我可以运行它。有没有办法让代码写在函数内部?
我正在使用 VScode 在 jupyter 上使用 keras_ocr。通过运行此代码:prediction_groups = pipeline.recognize(images) 我收到此错误消息“如何修复错误消息”在回复完成之前取消了execute_request消息的未来在当前单元格或上一个单元格中执行代码时内核崩溃细胞。请检查单元格中的代码以确定失败的可能原因。点击这里查看更多信息。查看 Jupyter 日志以获取更多详细信息。”有人可以帮我解决这个问题吗
解决内核问题
这是文件:https : //drive.google.com/file/d/0B5v-nJeoVouHc25wTGdqaDV1WW8/view?usp=sharing
如您所见,第一列中有重复项,但是如果我要合并重复的行,则其他列中不会覆盖任何数据。有什么办法可以将第一列中具有重复值的行合并?
例如,将“ 1,A,A,”和“ 1,,T,T”变成“ 1,A,A,T,T”。
I'm getting an error in Jupyter notebook:
from sklearn.impute import SimpleImputer
imputer= SimpleImputer(missing_values = 'NaN', strategy = 'mean', axis= 0)
Run Code Online (Sandbox Code Playgroud)
and my error is
TypeError Traceback (most recent call last)
<ipython-input-128-9f8271dfdf3c> in <module>
1 from sklearn.impute import SimpleImputer
----> 2 imputer= SimpleImputer(missing_values = 'NaN', strategy = 'mean', axis= 0)
TypeError: __init__() got an unexpected keyword argument 'axis'
Run Code Online (Sandbox Code Playgroud) 我已经在个人计算机上编写了一个脚本,以CSV格式组织办公室服务器中的一些PDF文件。
但是,我没有在办公室中安装Python,也没有安装它的权限。我当时正在考虑使用Jupyter Notebook之类的东西在浏览器上运行代码。
有什么方法可以在Jupyter笔记本(浏览器)的计算机上的文件夹中运行脚本?我需要执行此操作,而无需将文件上传到Jupyter实验室,并在目录上运行代码。
先感谢您!
您好,我刚开始使用 Jupyter 笔记本、python、matplotlib、pandas 和 seaborn。我正在尝试使用 seaborn 中的 displot 函数绘制密度图。我也希望能够看到直方图,但我想看到密度而不是 y 轴上的“计数”。旧的 distplot 函数自动显示密度,我只是不知道如何用新的 displot 来设置它。任何帮助将不胜感激!
开发总结此数据的频率分布。此数据是一个对象在 20 天内的需求。
2 1 0 2 1 3 0 2 4 0 3 2 3 4 2 2 2 4 3 0. 任务是在 jupyter notebook 中创建一个表,其中包含 Demand 和 Frequency 列。注意:需求必须按升序排列。这就是我所做的。
list_of_days = [2, 1, 0, 2, 1, 3, 0, 2, 4, 0, 3, 2 ,3, 4, 2, 2, 2, 4, 3, 0] # created a list of the data
import pandas as pd
series_of_days = pd.Series(list_of_days) # converted the list to series
series_of_days.value_counts(ascending = True) # the frequency was …Run Code Online (Sandbox Code Playgroud) 这可能是非常基本的事情,我不知道我做错了什么.
我有一本字典:
elSPH = {
'%SiO2': 52.79,
'%MgO': 0.10,
'%Na2O': 4.33,
'%Al2O3': 29.50
}
Run Code Online (Sandbox Code Playgroud)
我想为每个元素创建一个新的字符串行,如下所示:
%SiO2: 52.79
%MgO: 0.10
%Na2O: 4.33
%Al2O3: 29.50
Run Code Online (Sandbox Code Playgroud)
所以我试过了
''.join('{}{}\n'.format(key, val) for key, val in elSPH.items())
Run Code Online (Sandbox Code Playgroud)
得到输出:
'%SiO252.79\n%MgO0.1\n%Na2O4.33\n%Al2O329.5\n'
Run Code Online (Sandbox Code Playgroud)
有没有办法如何使这个新的换行工作?出于某种原因,它甚至没有处理一些简单的事情:
In: d = 'Hello\nworld'
In: d
Out: 'Hello\nworld'
Run Code Online (Sandbox Code Playgroud) 我正在尝试查找数据集中其中一列中所有值的平均值.我做了df ["column"].mean()但是它给了我一个可笑的大数字,考虑到我的价值有多小,这个数字没有意义.但是,min()和max()函数运行正常.
为了澄清,第一个单元格中输出的左侧是索引,右侧是值.
delay["If Delayed, for how long?"].astype(int)
print(delay["If Delayed, for how long?"].min())
print(delay["If Delayed, for how long?"].max())
print(delay["If Delayed, for how long?"].mean()
Run Code Online (Sandbox Code Playgroud) jupyter-notebook ×11
python ×11
pandas ×4
csv ×1
dataframe ×1
keras ×1
plot ×1
python-3.x ×1
seaborn ×1
statistics ×1
tensorflow ×1