【发布时间】:2020-11-29 17:39:09
【问题描述】:
我有一个大的CSV 文件,它是用 Dask 打开的。
import numpy as np
import pandas as pd
import hvplot.pandas
import hvplot.dask
import intake
data = '../file.csv'
ddf = intake.open_csv(data).to_dask()
ddf.head()
Datetime latitude longitude Temp_2m(C)
1 1980-01-02 03:00:00 30.605 50.217 5.31
2 1980-01-02 04:00:00 30.605 50.217 5.36
3 1980-01-02 05:00:00 30.605 50.217 7.04
4 1980-01-02 06:00:00 30.605 50.217 10.24
我想用 hvplot 每月绘制Temp_2m(C)。使用Datetime 的每小时数据绘制正确完成,但是当我想将Datetime 分组如下时,它返回错误。
# Convert 'Datetime' column to 'datetime64'
ddf["Datetime"] = ddf["Datetime"].astype("M8[us]")
# set index column
ddf = ddf.set_index('Datetime')
g = pd.Grouper(freq='M', key='Datetime')
month_ddf = dff.groupby(g).mean()
# plot
month_ddf.hvplot('Temp_2m(C)')
错误:
ValueError: all keys need to be the same shape
我的错误是什么?
回复@frankr6591:
month_ddf.describe()
Dask DataFrame Structure:
latitude longitude Temp_2m(C)
npartitions=1
float64 float64 float64
... ... ...
Dask Name: describe-numeric, 89 tasks
【问题讨论】:
-
请不要分享截图。他们很难帮助你。而是共享一些数据。
-
@Serge de Gosson de Varennes,感谢您的评论,我已编辑。
-
你做过month_ddf.describe()来看看它的形状吗?重新查看 ERROR 后,似乎 month_ddf 不统一。
-
@frankr6591,我在问题中添加了
month_ddf.describe()。 -
@HMadadi,请使用 print(month_ddf.describe()) 以便我们可以看到整个表格而不是“...”
标签: python pandas pandas-groupby dask hvplot