【问题标题】:How to get data from object/string format to int in pandas dataframe?如何在 Pandas 数据框中将数据从对象/字符串格式获取为 int?
【发布时间】:2021-04-07 05:48:11
【问题描述】:

我有一个看起来像这样的熊猫数据框:

我现在想将列 Predictions 设置为 int 值,以便绘制数据。我怎么能这样做?

【问题讨论】:

  • df['Predictions'].str[0].astype(int)

标签: python pandas string integer


【解决方案1】:

这只是 pandas 列的列表理解

你可以使用

df['Predictions'].str[0].astype(int)

提取十进制值

df['Predictions'].str[0]-df['Predictions'].str[0].astype(int)

【讨论】:

  • 谢谢!是否有可能保留逗号值?
  • 很高兴为您提供帮助,如果您只需要十进制值,可以使用df['Predictions'].str[0]-df['Predictions'].str[0].astype(int)
猜你喜欢
  • 2020-07-01
  • 2020-01-29
  • 1970-01-01
  • 2012-03-17
  • 2018-06-23
  • 2021-07-11
  • 2016-10-23
  • 2020-10-21
  • 2012-10-28
相关资源
最近更新 更多