具体代码(我是以一个数据较少的csv文件做了测试,具体的csv文件需要修改部分代码才能顺利实现)
import pandas as pd
df01 = pd.read_csv("D:\\12140\\Desktops\\111\\333\\333.csv", encoding="utf-8", dtype="str")
data = df01['新增'].fillna('no_zeng')
data2 = df01['GDP']
data3 = []
print(data)
for i in range(0, len(data)):
if data[i] == "no_zeng":
data3.insert(i, data2[i])
print(1)
print(data[i])
else:
data3.insert(i, data[i])
print(2)
print(data[i])
df01['GDP'] = data3
df01.to_csv("D:\\12140\\Desktops\\111\\333\\333.csv", index=False)
效果展示
在保留原本的列的数据的同时,还能够新添加入新的数据;
标签:到列,python,333,补充,print,csv,data,data3,df01 From: https://www.cnblogs.com/liuzijin/p/18091581