当你做-
df.insert(2,'new',1000)
它将
new列插入到
df内存中的Dataframe中(所有值均为1000)。它不会自动将其写回到csv。
对于对数据帧所做的更改以将其写回到csv,应使用
Dataframe.to_csv()method。范例-
def updatecsv(): files = 'example.cs' df = pd.read_csv(files) df = df.convert_objects(convert_numeric=True) #until here, the pre is running fine #now i wanted to add a new column in a specific index with all value =10 df.insert(2,'new',1000) df.to_csv(files)
另外,在尝试调用该函数之前,应确保已定义该函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)