如何在Python循环后保存更改?

huangapple go评论65阅读模式
英文:

How to save the changes after a loop in python?

问题

for i in data['test preparation course']:
    if i == 'none':
        i = None

在这里,我试图将字符串 'none' 转换为 Python 中的 None 值,而且成功了。

我只想在数据集上应用这些更改。

英文:

for i in data['test preparation course']:
if i == 'none':
i = None

here, I'm trying to convert 'none' string with None values in python, and it went well.

I just want to activate the changes on the dataset

答案1

得分: 2

请使用 pandas.Series.replace 函数:

data['test preparation course'].replace('none', None, inplace=True)
英文:

Instead, use pandas.Series.replace function:

data['test preparation course'].replace('none', None, inplace=True)

huangapple
  • 本文由 发表于 2023年5月14日 03:48:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定