1

I have this dataframe

    user_date   user_time
0   Thu         07:32:20
1   Wed         21:10:38
2   Fri         21:32:55
3   Sat         11:57:36
4   Fri         22:37:41

How to plot this dataframe with x is user_time with range 24hours and y is user_date.

In the meantime, thank you so much for your attention and participation.

1
  • is dataframe from csv? Commented Jun 23, 2017 at 7:01

1 Answer 1

1

There is problem with user_date values, because if use strings get:

TypeError: Empty 'DataFrame': no numeric data to plot

One possible solution is convert them to ordered categorical and plot by cat.codes.

Also plot timedelata is not implemented, so user_time was converted to to_datetime and then to strings by strftime:

days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
df['user_date'] = df['user_date'].astype('category', categories=days, ordered=True)

df['user_time1'] = pd.to_datetime(df['user_time']).dt.strftime('%H:%M:%S')
df['user_date1'] = df['user_date'].cat.codes

ax = df.plot(x='user_time1', y='user_date1')

#set max and min values of axis
#https://stackoverflow.com/a/43460067/2901002
ax.set_yticks(range(7))
ax.set_yticklabels(days)

graph

Sign up to request clarification or add additional context in comments.

7 Comments

Hi @jezrael, thanks for your help. I had this error: NameError: name 'ticker' is not defined The plot missing some data in dataframe. How to keep the user_time? I don't want to change to second.
Yes, it was not easy, but now it should work. Please check solution.
Hi, I had this error : ** _astype() got an unexpected keyword argument 'ors' **. I using Python 3, but after removing ors=True, categories =days everything ran fine! Thanks so much @jezrael
Do you think axis x? from 0 to 24?
I mean, I hope you can help me show all data of user_time. If I have 50 values of user_time, how to show all 50 value of that user on the plot ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.