I have a bunch of CSV files which are read as dataframes. For each dataframe, I want to change some column names, if a specific column exists in a dataframe:
column_name_update_map = {'aa': 'xx'; 'bb': 'yy'}
In such a map, if 'aa' or 'bb' exists in a dataframe, I want to change the aa to xx, and 'bb' to 'yy'. No values should be changed.
for file in files:
print('Current file: ', file)
df = pd.read_csv(file, sep='\t')
df = df.replace(np.nan, '', regex=True)
for index, row in df.iterrows():
pass
I don't think I should use the inner loop, but if I have to do, what's the right way to change the column name only?