gpt4 book ai didi

python - python 计算每一行的值

转载 作者:太空宇宙 更新时间:2023-11-03 14:24:56 33 4
gpt4 key购买 nike

我想计算每行的平均值,并将它们生成在每个数据帧的另一个新列中。 This is small sample of data that I am having我不知道应该如何编写一个可以逐行计算的函数,因为我的实际数据将有 600K 行之类的东西。

最佳答案

试试这个,

 df = pd.DataFrame([[2,1],[3,2],[4,3],[5,4]],columns=['B','A'],index=[1,2,3,4])
df['mean'] = df.mean(axis=1)
df
Output:
B A mean
1 2 1 1.5
2 3 2 2.5
3 4 3 3.5
4 5 4 4.5

关于python - python 计算每一行的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47706509/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com