gpt4 book ai didi

python - 从 Pandas 数据框中删除空行

转载 作者:行者123 更新时间:2023-12-04 17:44:45 26 4
gpt4 key购买 nike

我正在使用 this dataset并通过 Pandas 数据框读取它。我需要与 paperAbsrtract 一起工作仅包含一些缺失数据的列。

filename = "sample-S2-records"
df = pd.read_json(filename, lines=True)
abstract = df['paperAbstract']

因为 abstract里面有一些缺失的数据数据框,我想删除那些空的行。所以关注 documentation ,我在下面
abstract.dropna(how='all')

但这不会删除那些空行。他们还在 abstract数据框。我错过了什么?

最佳答案

您失踪了 inplace = True或将此函数的结果分配给您的数据框。

Solution 1: inplace = True:

abstract.dropna(how='all', inplace = True)
# do operation inplace your dataframe and return None.

Solution 2: assign the function result to your own dataframe:

abstract = abstract.dropna(how='all')
# don't do operation inplace and return a dataframe as a result.
# Hence this result must be assigned to your dataframe
注: inplace默认值为 False .

关于python - 从 Pandas 数据框中删除空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52655623/

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