将泰坦尼克号缺失数据补齐,这大致怎么写???
编写程序使用平均值法将泰坦尼克号数据集中年龄属性缺失值补齐 一切取决于你有什么,想要什么,怎么判断是否可接受。 ????????? 泰坦尼克号? PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked1 0 3 Braund, Mr. Owen Harris male 22 1 0 A/5 21171 7.25 S
2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38 1 0 PC 17599 71.2833 C85 C
3 1 3 Heikkinen, Miss. Laina female 26 0 0 STON/O2. 3101282 7.925 S
4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35 1 0 113803 53.1 C123 S
5 0 3 Allen, Mr. William Henry male 35 0 0 373450 8.05 S
6 0 3 Moran, Mr. James male 0 0 330877 8.4583 Q
7 0 1 McCarthy, Mr. Timothy J male 54 0 0 17463 51.8625 E46 S
8 0 3 Palsson, Master. Gosta Leonard male 2 3 1 349909 21.075 S
9 1 3 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27 0 2 347742 11.1333 S
10 1 2 Nasser, Mrs. Nicholas (Adele Achem) female 14 1 0 237736 30.0708 C
11 1 3 Sandstrom, Miss. Marguerite Rut female 4 1 1 PP 9549 16.7 G6 S
是这样一个表格呢
pandas 的 DataFram 有个fillna 方法可以补全缺失值,参考代码:
df.fillna(df.mean())
使用每列的均值进行填补缺失值,不是在原数据上进行填补
而是返回一个新的 DataFram,记得重新赋值为新的变量
Twilight6 发表于 2022-10-3 21:16
pandas 的 DataFram 有个fillna 方法可以补全缺失值,参考代码:
有链接吗{:10_254:} giegie666 发表于 2022-10-3 21:20
有链接吗
呃,我查查
giegie666 发表于 2022-10-3 21:20
有链接吗
参考文章:
https://blog.csdn.net/qq_17753903/article/details/89892631#:~:text=pandas%E4%B8%ADfillna%20%28%29%E6%96%B9%E6%B3%95%EF%BC%8C%E8%83%BD%E5%A4%9F%E4%BD%BF%E7%94%A8%E6%8C%87%E5%AE%9A%E7%9A%84%E6%96%B9%E6%B3%95%E5%A1%AB%E5%85%85NA%2FNaN%E5%80%BC%E3%80%82%201.%E5%87%BD%E6%95%B0%E8%AF%A6%E8%A7%A3%20%E5%87%BD%E6%95%B0%E5%BD%A2%E5%BC%8F%EF%BC%9Afillna%20%28value%3DNone%2C,method%3DNone%2C%20axis%3DNone%2C%20inplace%3DFalse%2C%20limit%3DNone%2C%20downcast%3DNone%2C%20%2A%2Akwargs%29
页:
[1]