import pandas as pd
import csv
colName = {
}
def save_columns_to(src_file, mid_file, columns=None):
df = pd.read_csv(src_file)
df[columns].to_csv(mid_file, index=None)
def changeColName(mid_file,columns):
all_data = pd.read_csv(mid_file,encoding='ANSI')
columns = all_data.columns
all_data.rename(columns=lambda x: colName.get(x, x), inplace = True)
all_data.to_csv(mid_file,encoding='ANSI')
def selectRow(mid_file,dst_file):
with open(mid_file, 'r', newline='') as csv_in_file:
with open(dst_file, 'w', newline='') as csv_out_file:
filereader = csv.reader(csv_in_file)
filewriter = csv.writer(csv_out_file)
header = next(filereader)
filewriter.writerow(header)
for row_list in filereader:
supplier = str(row_list[3]).strip()
if supplier == '':
filewriter.writerow(row_list)
if __name__ == '__main__':
src_file=r''
mid_file=r''
dst_file=r''
columns = []
save_columns_to(src_file, mid_file, columns)
changeColName(mid_file,columns)
selectRow(mid_file,dst_file)