0

I would like to format the values (they are a Pandas series) in a column.

When I run the following code on category_table which is a Pandas DataFrame

num_format = '{:,}' 

category_table = num_format.format(category_table['Forecast_Sales'])      

I get the following error

TypeError: unsupported format string passed to Series.__format__

I have looked on stack overflow for answer but have not had any luck

  • 1
    We have to go the other way with format. Instead of calling format on the _Series_ you need to apply the format to the _values_ in the column -> `category_table['Forecast_Sales'] = category_table['Forecast_Sales'].map(num_format.format)`. Note the linked thread also has several options that only change the display behaviour and not the underlying values. – Henry Ecker Sep 24 '21 at 17:56

0 Answers0