[问题] Pandas算平均值

楼主: shawn1116 (大同)   2021-06-06 18:06:03
自学新手想请问一下大家用dataFrame转成Series 在取平均要怎么算
怎么跑都不对Orz
====================================
import pandas as pd
data=pd.DataFrame({
"name":["Amy","Bob", "Charles"],
"salary":["30000","40000","50000"]
})
salaries=data["salary"]
print("薪水的平均值",salaries.mean())
============================================
这样算出来是100001333350000.0
Orz
截图 https://imgur.com/a/BRZPnzV
作者: Pieteacher (pieteacher)   2021-06-06 18:07:00
data.salary.squeeze().mean()
作者: andy19960407 (258698)   2021-06-06 18:08:00
为什么要用字串…
作者: chickengod (鸡大侠)   2021-06-06 20:08:00
"salary":["30000","40000","50000"] "30000" 是文字"30000" 是 string, 30000 才是 integer 整数data type 不对 所以取平均会错
作者: damnbear (tired)   2021-06-14 12:39:00
我觉得你要先去搞懂资料型态耶

Links booklink

Contact Us: admin [ a t ] ucptt.com