Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas qcut ValueError: Input array must be 1 dimensional

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading