How fix 'px' is not defined in Python plots from pivot table?

Viewed 34

I have this pivot table:

union3_pv1 = pd.pivot_table(union3,
              index = ['year', 'month', 'member_casual'],
              values = 'ride_id',
              aggfunc = ['count'],
              margins = True,
              margins_name = 'Total Count')
cm = sns.light_palette("green", as_cmap=True)
union3.style.background_gradient(cmap=cm)
union3_pv1 = union3_pv1.loc[(union3_pv1 != 0).any(axis=1)]
union3_pv1

I would like create bar chart from this pivot table:

fig_2 = union3.groupby(['year', 'month', 'member_casual'], as_index=False).count()
fig_2 = fig_2[fig_2['ride_id'] != 0]

px.line(fig_2, x = 'month', y = 'ride_id', range_y = [0,450000],
        color = 'member_casual', 
        line_shape = 'spline',
        markers=True, 
        labels = {'ride_id': 'No. of Rides', 'month': 'Months (Oct 2020 - Sep 2021)', 'member_casual': 'Member/Casual'},
        hover_name = 'member_casual', hover_data = {'member_casual': False, 'month': True, 'ride_id': True}, 
        color_discrete_map = {'casual': '#FF934F', 'member': '#058ED9'})

The error text: px

NameError Traceback (most recent call last) Input In [277], in <cell line: 4>()

1 fig_2 = union3.groupby(['year', 'month', 'member_casual'], as_index=False).count()
      2 fig_2 = fig_2[fig_2['ride_id'] != 0]
----> 4 px.line(fig_2, x = 'month', y = 'ride_id', range_y = [0,450000],
      5         color = 'member_casual', 
      6         line_shape = 'spline',
      7         markers=True, 
      8         labels = {'ride_id': 'No. of Rides', 'month': 'Months (Oct 2020 - Sep 2021)', 'member_casual': 'Member/Casual'},
      9         hover_name = 'member_casual', hover_data = {'member_casual': False, 'month': True, 'ride_id': True}, 
     10         color_discrete_map = {'casual': '#FF934F', 'member': '#058ED9'})

NameError: name 'px' is not defined

Second question - how can I change it to vertical bar chart please?

0 Answers
Related