当有两个索引、pandas、python 时针对日期时间进行绘图

Posted

技术标签:

【中文标题】当有两个索引、pandas、python 时针对日期时间进行绘图【英文标题】:plotting against datetime when there are two indices, pandas, python 【发布时间】:2018-06-10 16:37:25 【问题描述】:

我有如下所示的数据框,

                USD 
state    date
  AL     01/01    10
         01/08    15
           .
           .
           .
         12/30    8

  AK     01/01    10
         01/08    15
           .
           .
           .
         12/30    8

对于每个州。 我想在一张图中为每个州绘制日期与美元的关系。 我该怎么做?

【问题讨论】:

df.unstack().plot()? 【参考方案1】:

使用unstackplot

df.unstack(0).plot()

数据输入

df
Out[92]: 
             USD
state date      
AL    01/01   10
      01/08   15
      12/30    8
AK    01/01    3
      01/08    5
      12/30    2

【讨论】:

我错过了0。你明白了。 @cᴏʟᴅsᴘᴇᴇᴅ 哈哈新年快乐 :-) 正是我需要的。谢谢你们! @HirotakaNakagame 如果这是您需要的,您可以考虑投票并接受吗?:-)

以上是关于当有两个索引、pandas、python 时针对日期时间进行绘图的主要内容,如果未能解决你的问题,请参考以下文章

仅从数据框中选择每个月的最后一周 - Python/Pandas

将日期时间格式的索引转换为仅限日期的python pandas

python--pandas删除

Pandas:具有多个索引的滚动总和(即面板数据)

Python、Pandas:80/20 随机拆分数据;当索引值“丢失”时如何循环?

pandas常用