[英]Error creating a Crosstab in Python. TypeError: list indices must be integers or slices, not tuple
I'm trying to do a Crosstab and I'm getting the error TypeError: list indices must be integers or slices, not tuple
我正在尝试做一个交叉表,我收到错误
TypeError: list indices must be integers or slices, not tuple
I have already including parenthesis and brackets, but nothing works.我已经包括了括号和方括号,但没有任何效果。
This is the code这是代码
y1 = np.array([df_train[df_train['dep_delayed_15min'] == 'Y']['UniqueCarrier'].value_counts().values])
y2 = np.array([df_train[df_train['dep_delayed_15min'] == 'N']['UniqueCarrier'].value_counts().values])
y3 = y1+y2
y4 = y1/y3
y5 = y2/y3
y6 = set(df_train['UniqueCarrier'])
d = {'UniqueCarrier': [y6], 'Perc_Y': [y4], 'Perc_N': [y5]}
df = pd.DataFrame([d])
df.head()
pd.crosstab[df['UniqueCarrier'], df['Perc_Y'], df['Perc_N']]
This is what I get form df.head() that is not what I need for the next step, that is creating the crosstab with the numbers.这就是我从 df.head() 中得到的,这不是我下一步需要的,即用数字创建交叉表。
UniqueCarrier Perc_Y Perc_N
0 [{CO, FL, UA, DH, NW, B6, AS, DL, HP, EV, AA, ... [[[0.21343323166688768, 0.1879379910809089, 0.... [[[0.7865667683331123, 0.8120620089190911, 0.8...
Unless I'm very confused pd.crosstab is a function so should be invoked with parentheses除非我很困惑 pd.crosstab 是 function 所以应该用括号调用
pd.crosstab(df['UniqueCarrier'], df['Perc_Y'], df['Perc_N'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.