Python 如何在dataframe中将数据从对象/字符串格式转换为int?

Python 如何在dataframe中将数据从对象/字符串格式转换为int?,python,pandas,string,integer,Python,Pandas,String,Integer,我有一个熊猫数据框,看起来像这样: 现在我想将列Predictions设置为int值,以便绘制数据。我怎样才能做到这一点呢?这只是一个从熊猫栏中理解的列表 你可以用 df['Predictions'].str[0].astype(int) 提取十进制值的步骤 df['Predictions'].str[0]-df['Predictions'].str[0].astype(int) df['Predictions'].str[0].astype(int)谢谢!有可能保留逗号值吗?很高兴提供帮

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


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

这只是一个从熊猫栏中理解的列表

你可以用

df['Predictions'].str[0].astype(int)
提取十进制值的步骤

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

df['Predictions'].str[0].astype(int)谢谢!有可能保留逗号值吗?很高兴提供帮助,如果您只需要十进制值,可以使用
df['Predictions'].str[0]-df['Predictions'].str[0].astype(int)