Pandas Approach To Excel Filter
I have an example script below that I run on an excel file. Essentially after line 6 I want to filter out rows that contain BFD and SFD in Column F( I know just assigned these valu
Solution 1:
Untested, as there's no data given, but this should do the trick for you:
filtered = [d for d in data if d['F'] == 'BFD' or d['F'] == 'SF']
# now proceed with your work
Solution 2:
This will convert your data dataframe into a dataframe containing ONLY rows were column F has BDF or SDF
data = data[data.F.str.contains(r'^BFD$|^SFD$', case = False, na=False)]
Solution 3:
Thanks again for all the help, this is what I ended up doing. Please poke holes if you think this does not equate to an excel filter of filtering for items that start with UN making adjustments then clearing filters.
ta = data[~data.Format.str.contains(r'UN', case = False, na=False, regex = False)] # trying regex
da = data[data.Format.str.contains(r'UN', case = False, na=False, regex = False)] # trying regex
final = pd.concat([ta, da],0) # now append seperate dataframes
Post a Comment for "Pandas Approach To Excel Filter"