Dynamically Read Csv Files Python Pandas
I would like to iteratively read data from a set of csv files in a for loop. The csv files are named (1.csv, 2.csv and so on) The normal way to read the data will be data = pd.re
Solution 1:
Use either percent formatting
pd.read_csv('%d.csv' % i)
or format
pd.read_csv('{0}.csv'.format(i))
Solution 2:
make a separate string?
if i
is indeed an integer, using:
filename = str(i) + '.csv'
data=pd.read_csv(filename)
or even:
data=pd.read_csv(str(i)+'.csv')
should be fine :)
Post a Comment for "Dynamically Read Csv Files Python Pandas"