I am looking for efficient Python codes to:
1. Create multiple data frames 2. Loop over the multiple data frames
For instance, in my code:
os.chdir(EU_path)
csv_files = glob.glob(EU_path + '\*.csv')
list_EU_data = []
for filename in csv_files:
data = pd.read_csv(filename)
list_EU_data.append(data)
list_EU_data is a list of 10 csv files of product sales from 10 European countries. For instance, list_EU_data[0] returns a data frame with columns related to sales information.
Here, I want to create multiple data frames while pre-processing data frames, for instance,
First select columns
EU[0] = list_EU_data[0].iloc[:, [0, 1]]
EU[1] = list_EU_data[1].iloc[:, [0, 1]]
...continues...
EU[9] = list_EU_data[9].iloc[:, [0, 1]]
Next, from each of the data frames, I want to replace 0 values by 1 and iterate all the data frames:
EU[0].iloc[:, 1] = EU[0].iloc[:, 1].replace(0, 1)
EU[1].iloc[:, 1] = EU[1].iloc[:, 1].replace(0, 1)
...continues...
EU[9].iloc[:, 1] = EU[9].iloc[:, 1].replace(0, 1)
Using for loop, what's the most efficient ways to write the above code?
1. Create multiple data frames?