社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python-按月和日绘制多个数据帧(忽略年份)

Ijaz Ur Rahim • 7 年前 • 2149 次点击  

我有多个具有不同年份数据的数据帧。

数据帧中的数据是:

>>> its[0].head(5)
            Crocs
date             
2017-01-01     46
2017-01-08     45
2017-01-15     43
2017-01-22     43
2017-01-29     41

>>> its[1].head(5)
            Crocs
date             
2018-01-07     23
2018-01-14     21
2018-01-21     23
2018-01-28     21
2018-02-04     25

>>> its[2].head(5)
            Crocs
date             
2019-01-06     90
2019-01-13     79
2019-01-20     82
2019-01-27     82
2019-02-03     81

我试着用一个图形来绘制所有这些数据帧,是的,我完成了,但这不是我想要的。

我使用以下代码绘制了数据帧

>>> for p in its:
    plt.plot(p.index,p.values)
>>> plt.show()

我得到了下面的图表 Graph i Got by Combing all dfs

但这不是我想要的 我希望图表是这样的 Graph i want

简单地 我希望图表忽略年,按月和日绘制

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/47987
文章 [ 1 ]  |  最新文章 7 年前
Naga Kiran
Reply   •   1 楼
Naga Kiran    7 年前

您可以尝试根据月份和日期将datetime索引转换为timeseries整数并绘制

df3 = pd.concat(its,axis=1)
xindex= df3.index.month*30 + df3.index.day
plt.plot(xindex,df3)
plt.show()

如果您希望日期时间信息大于整数,可以将xtick添加到frame

labels = (df3.index.month*30).astype(str)+"-" + df3.index.day.astype(str)
plt.xticks(df3.index.month*30 + df3.index.day, labels)
plt.show()