python时间序列动图,时间序列图Python

I am using pandas and I want to make a time series plot. I have this dataframe, and I want to plot the date on the x-axis with the number of units on the y-axis. I am assuming I need to convert my date object to a datetime before I can make this plot.

df1_99.dtypes

date object

store_nbr int64

units int64

tavg int64

preciptotal float64

dtype: object

df1_99

date store_nbr units tavg preciptotal

101885 2014-10-13 1 2 49 0.00

101996 2014-10-14 1 1 67 0.00

102107 2014-10-15 1 0 70 0.00

102218 2014-10-16 1 0 67 0.87

102329 2014-10-17 1 3 65 0.01

解决方案

As your dates are strings you can use to_datetime to convert to datetime objects:

In [4]:

df['date'] = pd.to_datetime(df['date'])

df.info()

Int64Index: 5 entries, 101885 to 102329

Data columns (total 5 columns):

date 5 non-null datetime64[ns]

store_nbr 5 non-null int64

units 5 non-null int64

tavg 5 non-null int64

preciptotal 5 non-null float64

dtypes: datetime64[ns](1), float64(1), int64(3)

memory usage: 240.0 bytes

You can then plot this:

df.plot(x='date', y='units')

9oXHO.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值