Python modifies the header of csv files in batches

how Python3 batch modifies the header of csv files

the novice crawler crawled the data into the csv file, but later, if you want to update header
header, everything under the header is appended mode. Only header does not append
, but if you update the header field in append mode, you will append the updated header field to the end

.

this is crawled data. I want to update the header field in batch, but it cannot be repeated. The content can be repeated
. For example, I want to add a source field at the end. Is there a way to update only the header part of
python?

Apr.30,2021

reference file replacement: https://www.cnblogs.com/bigbe.
read into memory, change the first line, then write to the new file, and finally use os.system to move the file



import pandas as pd
file_path = 'heihe.csv'

df=pd.read_csv(file_path, header=0)
df.columns=["a","b","c","d","e","f"]
df.to_csv(file_path, index=False)
Menu