python3熊猫-#TypeError:Can';t转换为';int';对象隐式地访问str

python3熊猫-#TypeError:Can';t转换为';int';对象隐式地访问str,python,string,pandas,int,typeerror,Python,String,Pandas,Int,Typeerror,请您支持我澄清将所选数据帧列转换为字符串的正确方法好吗 数据帧“df”的“Product_ID”部分自动选择为整数 如果我使用以下语句: df['Product_ID']=df['Product_ID'].to_string() 生成错误: TypeError: Can't convert 'int' object to str implicitly 同样的问题由.astype(str)或.apply(str) 谢谢 首先,请注意to_string和.astype(str)做不同的事情to_

请您支持我澄清将所选数据帧列转换为字符串的正确方法好吗

数据帧“df”的“Product_ID”部分自动选择为整数

如果我使用以下语句:

df['Product_ID']=df['Product_ID'].to_string()
生成错误:

TypeError: Can't convert 'int' object to str implicitly
同样的问题由
.astype(str)
.apply(str)


谢谢

首先,请注意
to_string
.astype(str)
做不同的事情
to_string
返回单个字符串,
.astype(str)
返回带有字符串值的序列。你想做什么

第二,您对使用整数系列有多大把握?
df['Product\u ID'].dtype
返回什么

第三,你能试着发布一个可复制的例子吗?缩小导致问题的数据范围的一种方法:

for i,v in enumerate(df['Product_ID'].values):
    try:
        str(v)
    except TypeError:
        print i, v

谢谢你的及时回复。我使用了命令:TypeCheck=df.dtypes并验证了“Product_ID”是“int64”。。。我试图在字符串()中添加一个新列df['Project\u ID\u textcopy']=df['Project\u ID']。这个问题似乎是在我要求在同一行中重写列本身df['Project\u ID']=df['Project\u ID']时产生的。有趣的是,我仍然无法重现这个问题。