I have a checklist (.csv) and lots of files (.csv). I want to read files if they are in the checklist.
- Checklist dataframe has three columns: "Energy": np.int32,"Potential": string ,"Try": np.int32
- Files have meaningful names: "Energy_POtential_Try.extension", for instance: "10_MM_20.csv"
so far, I have used isin function of pandas, but it seems to read each column individually. I want my "if" condition to return "True" if specific row has all my intended Energy, Potential, and Try values.
for root, dirs, files in os.walk(CollectionDirectory, topdown=False):
for File in files:
Energy = int(File.split("_")[-3])
Potential = File.split("_")[-2]
Try= int(File.split("_")[-1])
if checklistDf.isin([Energy,Potential,Try]).any().all():
DfNew = pd.read_csv(File)
Aucun commentaire:
Enregistrer un commentaire