Home > front end >  Pandas qcut ValueError: Input array must be 1 dimensional
Pandas qcut ValueError: Input array must be 1 dimensional

Time:11-14

I was trying to categorize my values into 10 bins and I met with this error. How can I avoid this error and bin them smoothly?

Attached are samples of the data and code.

Data

JPM
2008-01-02  NaN
2008-01-03  NaN
2008-01-04  NaN
2008-01-07  NaN
2008-01-08  NaN
... ...
2009-12-24  -0.054014
2009-12-28  0.002679
2009-12-29  -0.030015
2009-12-30  -0.019058
2009-12-31  -0.010090

505 rows × 1 columns

Code

group_names = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
discretized_roc = pd.qcut(df, 10, labels=group_names)

CodePudding user response:

Pass column JPM and for only integer indicators of the bins use labels=False:

discretized_roc = pd.qcut(df['JPM'], 10, labels=False)

If need first column instead label use DataFrame.iloc:

discretized_roc = pd.qcut(df.iloc[:, 0], 10, labels=False)
  • Related