[英]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.我试图将我的值分类为 10 个箱子,但我遇到了这个错误。 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)
Pass column JPM
and for only integer indicators of the bins use labels=False
:传递JPM
列,并且只有 integer 个 bin 指标使用labels=False
:
discretized_roc = pd.qcut(df['JPM'], 10, labels=False)
If need first column instead label use DataFrame.iloc
:如果需要第一列而不是 label 使用DataFrame.iloc
:
discretized_roc = pd.qcut(df.iloc[:, 0], 10, labels=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.