Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';我试图用pandas TimeGrouper创建一些日期的频率表,但它返回错误_Python_Pandas_Time - Fatal编程技术网

Python I';我试图用pandas TimeGrouper创建一些日期的频率表,但它返回错误

Python I';我试图用pandas TimeGrouper创建一些日期的频率表,但它返回错误,python,pandas,time,Python,Pandas,Time,我试图通过pandas TimeGrouper根据一些日期创建频率表,但收到以下错误 输入: t = pd.to_datetime(t) t = pd.Series(t) t 0 2019-04-10 10:49:00 1 2019-04-10 10:49:00 2 2019-04-10 10:49:00 3 2019-04-10 10:49:00 4 2019-04-10 10:49:00 5 2019-04-10 10:48:00 6 2019-

我试图通过pandas TimeGrouper根据一些日期创建频率表,但收到以下错误

输入:

t = pd.to_datetime(t)

t = pd.Series(t)

t
0   2019-04-10 10:49:00

1   2019-04-10 10:49:00

2   2019-04-10 10:49:00

3   2019-04-10 10:49:00

4   2019-04-10 10:49:00

5   2019-04-10 10:48:00

6   2019-04-10 10:48:00

7   2019-04-10 10:48:00

8   2019-04-10 10:48:00

9   2019-04-10 10:48:00

Name: tweet.created_at, dtype: datetime64[ns]
t.groupby(pd.core.resample.TimeGrouper('H').count().plot(kind='bar'))
Error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
输出:

t = pd.to_datetime(t)

t = pd.Series(t)

t
0   2019-04-10 10:49:00

1   2019-04-10 10:49:00

2   2019-04-10 10:49:00

3   2019-04-10 10:49:00

4   2019-04-10 10:49:00

5   2019-04-10 10:48:00

6   2019-04-10 10:48:00

7   2019-04-10 10:48:00

8   2019-04-10 10:48:00

9   2019-04-10 10:48:00

Name: tweet.created_at, dtype: datetime64[ns]
t.groupby(pd.core.resample.TimeGrouper('H').count().plot(kind='bar'))
Error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
输入:

t = pd.to_datetime(t)

t = pd.Series(t)

t
0   2019-04-10 10:49:00

1   2019-04-10 10:49:00

2   2019-04-10 10:49:00

3   2019-04-10 10:49:00

4   2019-04-10 10:49:00

5   2019-04-10 10:48:00

6   2019-04-10 10:48:00

7   2019-04-10 10:48:00

8   2019-04-10 10:48:00

9   2019-04-10 10:48:00

Name: tweet.created_at, dtype: datetime64[ns]
t.groupby(pd.core.resample.TimeGrouper('H').count().plot(kind='bar'))
Error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
输出:

t = pd.to_datetime(t)

t = pd.Series(t)

t
0   2019-04-10 10:49:00

1   2019-04-10 10:49:00

2   2019-04-10 10:49:00

3   2019-04-10 10:49:00

4   2019-04-10 10:49:00

5   2019-04-10 10:48:00

6   2019-04-10 10:48:00

7   2019-04-10 10:48:00

8   2019-04-10 10:48:00

9   2019-04-10 10:48:00

Name: tweet.created_at, dtype: datetime64[ns]
t.groupby(pd.core.resample.TimeGrouper('H').count().plot(kind='bar'))
Error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'

我用这个技巧四处走动:

t.reset_index().set_index(t.name).resample('H').count().plot()

不推荐使用“TimeGrouper”。嗯。现在我浏览了你的链接并使用了:t.groupby(pd.Grouper(freq='H')).count().plot()同样的错误。它返回了以下错误:返回self.\u engine.get\u loc(键)。关键错误:1抱歉,这是因为
t
的名称不同,请尝试
set\u index('tweet.created\u at')
而不是
set\u index(1)
。或者更一般地说
set\u index(t.name)
。1。我与中国无关。2.如果它有效,请考虑投票并接受答案:- 1。越南万岁。当然可以,兄弟。我投票了,但由于我的水平还不高,网站说我的投票将被考虑,但不会显示。再次非常感谢!