0

I have to use qcut with a column called "PriceEuro", the combination of qcut and "PriceEuro" should be in another column that it must be created. The new column is called "Price_Category". The column "Price_Category" should contain one of these three labels: low, medium or high.

I checked here in stackoverflow and I found this:

Assignment of qcut as new column

After reading the previous link I did the following thing:

import pandas as pd

new_labels = ['low','medium','high']

new_column = pd.qcut(df_csv3.rank(method='first')['PriceEuro'], q=5, labels=new_labels, duplicates='drop')

df_csv3 = df_csv3.assign(Price_Category=new_column.values)

But, once I run it i get the following ValueError:

first not supported for non-numeric data

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Maria
  • 17
  • 3
  • [This](https://stackoverflow.com/questions/20158597/how-to-qcut-with-non-unique-bin-edges) might help. – farshad Dec 27 '22 at 15:07
  • I put this: import pandas as pd new_labels = ['low','medium','high'] new_column = pd.qcut(df_csv3.rank(method='first')['PriceEuro'], q=5, labels=new_labels, duplicates='drop') df_csv3 = df_csv3.assign(Price_Category=new_column.values) And I get: ValueError: first not supported for non-numeric data – Maria Dec 27 '22 at 18:01

0 Answers0