【问题标题】:How can I change the information in a pandas.core.frame.DataFrame table with python?如何使用 python 更改 pandas.core.frame.DataFrame 表中的信息?
【发布时间】:2016-10-28 10:20:37
【问题描述】:

例如,我想把这张表中的所有信息都数字化:

0   30  "blue-collar"   "married"   "basic.9y"  "no"    "yes"   "no"    "cellular"  "may"   "fri"

Yes 更改为1no 更改为0basic.9y 更改为9

【问题讨论】:

  • 您的问题不清楚,您能否发布原始数据、创建 df 的代码、所需结果和您的尝试

标签: python pandas machine-learning


【解决方案1】:

您可以使用replaceastype 来做到这一点。

replace({'Yes':1, 'No':0, 'basic.9y':9}, inplace=True)

【讨论】:

  • 那么astype 是不必要的。但我认为它更复杂,因为你需要更换cellularfri...
  • 谢谢,我只想到astype 用于任何不变成数字的数据。关于其他数据是他的选择...
  • 对不起,我是 Stack Overflow 的初学者。我将详细添加所有条件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-13
  • 1970-01-01
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
相关资源
最近更新 更多