Question: Create a loop to process multiple files I have written the code below but currently I need to retype the same conditions for each file
Create a loop to process multiple files
I have written the code below but currently I need to retype the same conditions for each file and, as there are over 100 files, this is not ideal.
I couldn't come up with a way to implement this using a loop that will read all of these files and filter the values in MP out. Meanwhile, adding two new columns to each filter file as the written code below would be the only method I know so far. I try to obtain a new combined data frame with all filter files with their conditions
Please suggest ways of implementing this using a loop:

import pandas as pd import matplotlib.pyplot as plt import numpy as np from scipy import signal dfi = pd.read_csv('E:\Unmanned Cars\Unmanned Cars\2017040810_052.csv') df2 = pd.read_csv('E:\Unmanned Cars\Unmanned Cars\2017040901_052.csv') df3 = pd.read_csv('E:\Unmanned Cars\Unmanned Cars\2017040902_052.csv') df1 =df1["MP"].unique) df1=pd.DataFrame(dfi, columns=['MP']) df1["Dates"] = "2017-04-08" df1["Inspection"] = "10" ## df2 =df2["MP"]. unique) df2=pd.DataFrame(df2, columns=['MP']) df2["Dates"] = "2017-04-09" df2["Inspection"] = "01" ## df3 =df3["MP"]. unique) df3=pd. DataFrame(df3, columns=['MP']) df3["Dates"] = "2017-04-09" df3["Inspection"] = "02" Final = pd.concat([dfi, df2, df3, df4], axis = 0, sort = False)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
