Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn - TypeError: Invalid object type at position 0

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.

like image 730
Stanislav Jirák Avatar asked Oct 31 '25 19:10

Stanislav Jirák


2 Answers

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.

like image 97
rushikesh maheshwari Avatar answered Nov 03 '25 09:11

rushikesh maheshwari


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)
like image 33
Antonny Muiko Avatar answered Nov 03 '25 10:11

Antonny Muiko