Issue
I want to plot this dataframe like a time series, a line for every country that every year increases or decreases according to 'count'. How can i do this?
country count
Year
2005 Australia 2
2005 Austria 1
2005 Belgium 0
2005 Canada 4
2005 China 0
2006 Australia 3
2006 Austria 0
2006 Belgium 1
2006 Canada 5
2006 China 2
2007 Australia 5
2007 Austria 1
2007 Belgium 2
2007 Canada 6
2007 China 3
Solution
You can use seaborn.lineplot
:
import seaborn as sns
df.Year = pd.to_datetime(df.Year)
sns.set(rc={'figure.figsize':(12, 8)}) # changed the figure size to avoid overlapping
sns.lineplot(data=df, x=df['Year'].dt.strftime('%Y'), # show only years with strftime
y=df['count'], hue='country')
Answered By - Nuri Taş
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.