I have a dataframe that has values like this:
I want to make a multiple line graph that shows the average ride_length for each day for each customer type(member, casual). I tried to groupby day_of_week and member_casual columns like this:
avg_ride_length = df.groupby(['member_casual','day_of_week'])['ride_length'].mean() avg_ride_length.to_frame()
The output is this:
I tried alot but i couldn't make a multiple line graph like this:
If I understand what you are looking for, try this:
import pandas as pd
import matplotlib.pyplot as plt
avg_ride_length = data.groupby(['member_casual','day_of_week'])['ride_length'].mean().to_frame()
avg_ride_length_pivot = pd.pivot_table(avg_ride_length.reset_index(),
index='day_of_week', columns='member_casual', values='ride_length').plot()
plt.show()
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.