Pandas 在seaborn中绘制重采样数据

Pandas 在seaborn中绘制重采样数据,pandas,time-series,seaborn,resampling,Pandas,Time Series,Seaborn,Resampling,我有一个熊猫数据框架和一些金融业务。其中一列是“日期”。我把每天的数据重新采样成几个月 transfers_all.set_index(pd.DatetimeIndex(transfers_all['Date']), inplace = True) monthly = transfers_all.resample('M') 然而,当我试图用Seaborn绘制这些数据时,就像这样 monthly_plot = sns.lineplot(data = monthly,

我有一个熊猫数据框架和一些金融业务。其中一列是“日期”。我把每天的数据重新采样成几个月

transfers_all.set_index(pd.DatetimeIndex(transfers_all['Date']), inplace = True)

monthly = transfers_all.resample('M')
然而,当我试图用Seaborn绘制这些数据时,就像这样

monthly_plot = sns.lineplot(data = monthly,
                      x = 'Date',
                      y = 'Amount'
                      )
我得到一个错误:


AttributeError:'DatetimeIndexResampler'对象没有属性'get'

如果我尝试绘制整个数据帧,x轴显示天,但我想将它们分组为月。有没有办法从Seaborn内部重新采样,或者让Seaborn处理我的重新采样数据

运行
print(将\u all.head()传输到\u dict())
将提供以下输出:

{‘附加备注’:{时间戳('2017-01-02 00:00:00'):nan},'Data faktur':{时间戳('2017-01-02 00:00'):nan},'Data faktury':{时间戳('2017-01-02 00:00:00'):'-','Date':{时间戳('2017-01-02 00:00:00'):时间戳('2017-01-02 00:00:00'),'费用说明:{时间戳('2017-01-01-02 00:00:00:00'):'Opń“费用类别(标签):{Timestamp('2017-01-02 00:00:00'):'ADMIN','Komu zwrot':{Timestamp('2017-01-02 00:00:00'):'KG','Kwota(PLN):{Timestamp('2017-01-02 00:00:00'):3.0},'Kwota VAT(PLN):{Timestamp('2017-01-02 00:00:00'):nan},'Kwota w walucie oryginalnej':{Timestamp('2017-01-02-02 00:00:00'):nan('2017-01-02 00:00:00'):'-','Numer faktury':{Timestamp('2017-01-02 00:00'):'-','Opis wydatku':{Timestamp('2017-01-02 00:00'):nan}


我认为需要一些聚合函数,如
sum
mean
,其中包含
DatetimeIndex
中的for列:

transfers_all['Date'] = pd.to_datetime(transfers_all['Date'])
monthly = transfers_all.resample('M', on='Date').size().reset_index(name='count')

monthly_plot = sns.lineplot(data = monthly,
                      x = 'Date',
                      y = 'count'
                      )

我试过了。使用.sum()我得到了以下错误:>ValueError:无法用解释输入'Date'。count它显示一个绘图,但x轴不再是一个时间序列,而是一些其他数字,可能是counted Date。它太长了,无法在注释中发布,因此我将使用.sum()编辑OPIt,但在.count()上失败。我想看看每月事务的数量如何随时间变化>AttributeError:'DatetimeIndexResampler'对象没有属性'reset_index'@kuleje-oops,我的打字错误,需要
monthly=transfers_all.resample('M','on='Date').size().reset_index(name='count')