Python Forum
Buliding a dataframe with where conditions - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Buliding a dataframe with where conditions (/thread-30506.html)



Buliding a dataframe with where conditions - cspower - Oct-23-2020

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)



RE: Buliding a dataframe with where conditions - scidam - Oct-23-2020

If you need to choose rows by condition use loc instead:
df = df.loc[filter_1 & filter_2]



RE: Buliding a dataframe with where conditions - cspower - Oct-26-2020

(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.