How to add a new column to an individual file before concatenating these files

Viewed 15

def wrangle(filepath): df= pd.read_csv(filepath)

return df

files = glob("C:/Users/YBUCK MAX/Desktop/Python Project/World Disaster Risk/*.csv") files

from itertools import cycle year = cycle([2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021]) df['year'] = [next(year) for file in range(len(df))]

I will like to attach a new column having single value of year for each file

0 Answers
Related