There are multiple csv files in which I want to delete entire rows based on some specific keywords contained in rows. If the csv files contain x
, p
or z
in any row delete the entire row. It will loop through all csv files. Sample dataset:
>> df
k y j
0 a NaN x
1 p v z
2 m n 9
Expected outcome:
k y j
0 m n 9
I tried:
import os
import glob
import pandas as pd
os.chdir(r'mypath')
allFiles = glob.glob("*.csv")
for file in allFiles:
df = pd.read_csv(file)
#then no idea what to do
Try:
df = df[(df.ne("x")&df.ne("p")&df.ne("z")).all(axis=1)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.