I have a dataframe that looks like this:
Index Andy Bobby Charlie
0 2019-01-02 2019-01-01 2019-01-15
1 2019-01-05 2019-01-04 2019-01-17
2 2019-01-06 2019-02-03 2019-02-14
...
103 2019-07-01 2019-06-03 NaT
104 2019-07-06 NaT NaT
105 2019-07-23 NaT NaT
The dates are when each person had a meeting with a client. I want to create a plot of line graphs that chart how many meetings each person had since year to date.
I'm having trouble with the plotting syntax, also the NaT values are making it tough to graph every column? New to Python so would appreciate any help, thank you.
It might be easier to transpose the dataframe such that the datetimes are the indices, but I am not too sure how to do that either.
You can loop through every column of your dataframe, drop the missing values with dropna()
, reset the index (and add 1 = number of meetings) and plot it... like you correctly said with values and index reversed:
fig = plt.figure()
for c in df:
person = df[c].dropna().reset_index(drop=True)
person.index = person.index+1
plt.plot(person.values, person.index)
plt.xlabel('Date')
plt.ylabel('Number of Meetings')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.