[英]data Frame to csv file not including the numbers (floats in the table) and cleaning '\n'
我正在嘗試將 pandas 中的數據幀保存到 csv 文件,但是表中的數字未寫入文件在此處輸入圖像描述
即使在進行替換以清除表中的“\ n”之后,它仍然無法正常工作
final_product = income_df2.replace('[\n$,)]','', regex=True )\
.replace( '[(]','-', regex=True)\
.replace( '', 'NaN', regex=True)
您需要在每列中替換\n ,並將列轉換為數字
final_product = pd.to_numeric(income_df2.replace('\n', '',regex=True))
如果需要,將任何 NaN 替換為某個值(在本例中為 0)
final_product.fillna(0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.