Lowercase names of data columns within a list
I have several csvs, so I used glob and read_csv, add each one to the list, and then concatenate all of them.
My question is, how can I access column names and lowercase ones?
EDIT:
allfiles = glob.glob("*.csv", )
dataframes = []
for file in allfiles :
dataframes.append(pd.read_csv(file, sep=";", decimal=","))
df = pd.concat(dataframes)
Thank!
source to share
To rename columns you can use rename()
DataFrames method .
Here's an example:
df.rename(columns={colname:colname.lower() for colname in df.axes[1]})
It uses a list of column names ( df.axes[1]
) to create a dict
mapping of the old column names to their newer, lower-sized versions. The method then rename()
returns a copy of the dataframe with the renamed columns.
Note that it rename()
has a flag inplace
if you would rather edit the data block in place than return a copy.
source to share