简体   繁体   English

Sum() 返回df中最后一列的副本?

[英]Sum() returning a copy of the last column in df?

I am new to pandas and seem to get a repeated column rather than the sum of two.我是 pandas 的新手,似乎得到一个重复的列,而不是两个的总和。 CSV result CSV结果

df = pd.read_csv('0xb4a0a46d3042a739ec76fd67a3f1b99cc12ac1d9_mcap.csv', sep=',')

df1 = df.copy(deep=True)

df2 = df1.loc[:, ('mcap_token0', 'mcap_token1')]

df2 = df2.reset_index(drop=True)

df2.loc[:, 'sum'] = df2.sum(axis=1)

It's working fine, just you don't see it behind the decimals它工作正常,只是你在小数点后面看不到它在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM