Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python显示错误的输出_Python_Pandas - Fatal编程技术网

Python显示错误的输出

Python显示错误的输出,python,pandas,Python,Pandas,我使用的是groupby sum,但得到的输出错误: 虽然奖牌列仅包含0或1的值,但我在执行以下代码后获得此输出 test=oly_new.groupby(['Country','Year'])['Medal'].sum() 您的奖牌列是一个str,首先转换为int,然后求和: oly_new['Medal'] = oly_new['Medal'].astype(int) test=oly_new.groupby(['Country','Year'])['Medal'].sum() 当您的

我使用的是groupby sum,但得到的输出错误:

虽然奖牌列仅包含
0
1
的值,但我在执行以下代码后获得此输出

test=oly_new.groupby(['Country','Year'])['Medal'].sum()

您的
奖牌
列是一个
str
,首先转换为
int
,然后求和:

oly_new['Medal'] = oly_new['Medal'].astype(int)
test=oly_new.groupby(['Country','Year'])['Medal'].sum()

当您的列
dtype
str
时,
sum
函数只是将所有字符串连接起来您的
emdal
列为
str
,首先转换为
int
,然后进行求和:

oly_new['Medal'] = oly_new['Medal'].astype(int)
test=oly_new.groupby(['Country','Year'])['Medal'].sum()

当您的列
dtype
str
时,
sum
函数只是将所有字符串串联起来

请阅读请阅读,为了将来参考,不允许发布图像。您应该发布原始数据、重新创建df的代码、所需输出以及现有代码。也请记住接受我的回答,在我的回答的左上角的向下箭头下会有一个空勾号。此外,为了将来的参考,张贴图片是不允许的。您应该发布原始数据、重新创建df的代码、所需输出以及现有代码。还记得接受我的答案,在我的答案左上角的向下箭头下会有一个空勾号