【发布时间】:2019-10-20 12:04:41
【问题描述】:
我有一段代码如下所示:
import pandas as pd
file = pd.read_csv("/my/path/to/spreadsheet.csv", index_col=0)
file = file.dropna(how="any", inplace=True)
file = file.fillna("", inplace=False)
print(file)
预期输出:
Profit ($) Spendings ($) Total Profit EOY Profit ($)
Month
Jan 200 80 120 3150
Feb 310 50 260
Mar 250 40 210
Apr 170 70 100
May 650 200 450
Jun 180 150 30
Jul 530 160 370
Aug 610 270 340
Sep 470 180 290
Oct 680 290 390
Nov 570 310 260
Dec 600 270 330
电流输出:
Traceback(最近一次调用最后一次): 文件“/my/path/to/OpenSheet.py”,第 5 行,在 file = file.fillna("", inplace=False) AttributeError: 'NoneType' 对象没有属性 'fillna'
我知道这意味着当我执行file = file.dropna(how="any", inplace=True) 时,它以某种方式变成了NoneType 对象,但这是为什么呢?
另外,谁能告诉我如何获得预期的输出?
【问题讨论】:
-
阅读有关“inplace”参数的文档。
标签: python python-3.x pandas