I have the following df:
subject_id | name | day | value |
---|---|---|---|
1 | sld | 0 | 0 |
1 | sld | 1 | 5 |
1 | sld | 2 | 12 |
1 | dsld | 0 | 0 |
1 | dsld | 1 | -1 |
2 | sld | 0 | 0 |
2 | sld | 1 | 7 |
2 | sld | 2 | 8 |
2 | sld | 3 | 4 |
2 | dsld | 0 | 0 |
I want to make a line plot with the following criteria:
subject_id
name == sld
x
is the day
, and y
is the value
I want to plot all the groups on the same plot. Preferably using seaborn
fig, ax = plt.subplots(figsize=(8, 6))
df_sld = df[df['name'] == 'sld']
df_sld.groupby('subject_id').plot(x = 'day', y = 'value', ax = ax)
However, this is taking a long time. Is there a faster way to group by subject_id
and then only take the rows where name == sld
I also tried
df.groupby('subject_id')['name'].apply(lambda x: x == 'sld').plot(x = 'day', y = 'value')
df.groupby('subject_id').apply(lambda x: x['name'] == 'sld').plot(x = 'day', y = 'value')
But get an error saying no numerical data
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.