I'm trying to create a line chart from the data below with the date on the x-axis, score on the y-axis and a line for each value of X
X Date Score
1 A 2019-06-01 80
2 A 2019-05-01 70
3 A 2019-04-01 60
4 B 2019-06-01 90
5 B 2019-05-01 50
6 B 2019-04-01 70
I have tried df.groupby('X').head().plot.line(x='Date', y='Score'). Is it necessary to pivot the table so each value of X is a new column heading?
You could use Seaborn's lineplot with hue option set to your specific column X, like:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = {'X':['A', 'A', 'A', 'B', 'B', 'B'],
'Date' :['2019-06-01', '2019-05-01', '2019-04-01', '2019-06-01', '2019-05-01', '2019-04-01'],
'Score': [80, 70, 60, 80, 50, 70]}
df = pd.DataFrame.from_dict(data)
ax = sns.lineplot(x="Date", y="Score", hue="X", data=df)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With