Python Forum

Full Version: Buliding a dataframe with where conditions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to build a data-frame from csv file by selecting only the rows where one column is = to a string and a 2nd column has no value. The code below is supposed to only show the rows that match the conditions but it returns all the rows.
def match_db_groups(Users, Path, Dir, Processed_File):
    Missing_Group = path.join('/', Users, Path, Dir, Processed_File)  
    df = pd.read_csv(Missing_Group)
    filter_1 = df['DATABASE_TYPE'] == 'ORACLE'
    filter_2 = df['LOB'].isnull( == True)
    df.where(filter_1 & filter_2, inplace = True)
    print(df)
If you need to choose rows by condition use loc instead:
df = df.loc[filter_1 & filter_2]
(Oct-23-2020, 11:44 PM)scidam Wrote: [ -> ]If you need to choose rows by condition use loc instead:
df = df.loc[filter_1 & filter_2]

thank you that works.