I have a dataframe which looks like:
df_g_fcl.head()
Out[47]:
month_year producttype fpd_30 fpd_90 fstpd_90
4 2020-01 FCL 70.0 10.0 10.0
11 2020-02 FCL 9.0 0.0 0.0
18 2020-03 FCL 28.0 6.0 15.0
25 2020-04 FCL 14.0 3.0 11.0
33 2020-05 FCL 10.0 4.0 14.0
And I want to display a chart x=month_year, y=fpd_30 with forecast.
I tried:
plt.figure(figsize=(21, 8))
ax = sns.lineplot(x='month_year', y='fpd_30', data=df_g_fcl)
ax.tick_params(axis='x', labelrotation=90)
which yielded:
TypeError: Invalid object type at position 0
Help would be appreciated.
try this :
plt.figure(figsize=(21, 8))
ax = sns.lineplot(x=df_g_fcl['month_year'].astype(str), y=df_g_fcl['fpd_30'])
ax.tick_params(axis='x', labelrotation=90)
casting as string should help.
Seaborn and Matplotlib don't natively support plotting with periods, ie discrete data. You can convert the month_year column to DateTime.
df_g_fcl["month_year"] = pd.to_datetime(df_g_fcl["month_year"], format='%Y-%m')
fig, ax = plt.subplots(figsize=(10, 8))
sns.lineplot(x='month_year', y='fpd_30', data=df_g_fcl, ax=ax)
ax.tick_params(axis='x', labelrotation=90)
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