0
dd=df.select(df.Color,df.ListPrice.cast("float"))
colordf = dd[['Color','ListPrice']]
colordfgroup = colordf.groupby('Color').mean('ListPrice')
colordfgroup.show()

my_plot = colordfgroup.plot(kind='bar')

It shows me that DataFrame has no attribute plot.

All data frame type is a string.

1 Answers1

0

I commented the line colordfgroup.show() and corrected mean calculation

    dd=df.select(df.Color,df.ListPrice.cast("float"))
    colordf = dd[['Color','ListPrice']]
    colordfgroup = colordf.groupby('Color')['ListPrice'].mean()
    #colordfgroup.show()

    my_plot = colordfgroup.plot(kind='bar')

Here is a minimal example

import pandas as pd
import matplotlib.pyplot as plt
colors = ['A', 'B', 'C', 'D', 'A', 'B', 'C', 'D',  ]
lp     = [10.0, 20.0, 30.0, 40.0, 12.0, 22.0, 32.0, 42.0 ]
colordf = pd.DataFrame(data = {'Color': colors, 'ListPrice':lp}, index = [x for x in range(len(colors))])
colordfgroup = colordf.groupby('Color')['ListPrice'].mean()
my_plot = colordfgroup.plot(kind='bar')
Sowmya
  • 91
  • 1
  • 9