Can Pandas plot a histogram of dates?

前端 未结 8 1411
我在风中等你
我在风中等你 2020-11-28 03:15

I\'ve taken my Series and coerced it to a datetime column of dtype=datetime64[ns] (though only need day resolution...not sure how to change).

i         


        
相关标签:
8条回答
  • 2020-11-28 04:16

    All of these answers seem overly complex, as least with 'modern' pandas it's two lines.

    df.set_index('date', inplace=True)
    df.resample('M').size().plot.bar()
    
    0 讨论(0)
  • 2020-11-28 04:22

    I think resample might be what you are looking for. In your case, do:

    df.set_index('date', inplace=True)
    # for '1M' for 1 month; '1W' for 1 week; check documentation on offset alias
    df.resample('1M', how='count')
    

    It is only doing the counting and not the plot, so you then have to make your own plots.

    See this post for more details on the documentation of resample pandas resample documentation

    I have ran into similar problems as you did. Hope this helps.

    0 讨论(0)
提交回复
热议问题