Dynamically read csv files python pandas

csv, pandas, python

Solution

Use either percent formatting

 pd.read_csv('%d.csv' % i)

or `format`

 pd.read_csv('{0}.csv'.format(i))

Problem

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.read_csv('1.csv')` Please can someone suggest how to replace `1` by `i` when using a `for` loop. I tried `data = pd.read_csv(i+'.csv')` and `data = pd.read_csv(i'.csv')` but they did not work.

Original source