我有一个数据框,其中很少列具有混合类型值string + float,当我写入to_excel时,在excel enter image description here中写入后会收到此通知
这是数据框
df = placementsummaryfinalnew.loc[:,["Placement# Name","PRODUCT","Engagements Rate",
"Viewer CTR","Engager CTR","Viewer VCR",
"Engager VCR","Interaction Rate","Active Time Spent"]]
我尝试使用少量行
来转换它们placementvdxsummaryfirst["Viewer VCR"] = placementvdxsummaryfirst["Viewer VCR"].astype(object)
它不起作用
然后我尝试了这个。placementvdxsummaryfirst["Viewer VCR"] = placementvdxsummaryfirst["Viewer VCR"].astype(float)
给出错误
然后我尝试了这个。placementvdxsummaryfirst['Viewer VCR'] = pd.to_numeric(placementvdxsummaryfirst['Viewer VCR'],errors='coerce')
它的工作,但它取代了" N / A"空白的价值观,我不想要。
请帮助。
答案 0 :(得分:0)
尝试:
placementvdxsummaryfirst["Viewer VCR"] = placementvdxsummaryfirst["Viewer VCR"].astype(str)