pandas scatter plotting datetime

后端 未结 5 2059
长情又很酷
长情又很酷 2020-12-03 03:01

I have a dataframe with two columns of datetime.time\'s. I\'d like to scatter plot them. I\'d also like the axes to display the times, ideally. But

df.plo         


        
5条回答
  •  眼角桃花
    2020-12-03 03:20

    Not an answer, but I can't edit the question or put this much in a comment, I think.

    Here is a reproducible example:

    from datetime import datetime
    import pandas as pd
    df = pd.DataFrame({'x': [datetime.now() for _ in range(10)], 'y': range(10)})
    df.plot(x='x', y='y', kind='scatter')
    

    This gives KeyError: 'x'.

    Interestingly, you do get a plot with just df.plot(x='x', y='y'); it chooses poorly for the default x range because the times are just nanoseconds apart, which is weird, but that's a separate issue. It seems like if you can make a line graph, you should be able to make a scatterplot too.

    There is a pandas github issue about this problem, but it was closed for some reason. I'm going to go comment there and see if we can re-start that conversation.

    Is there some clever work-around for this? If so, what?

提交回复
热议问题