Python Forum
Buliding a dataframe with where conditions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Buliding a dataframe with where conditions
#1
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)
Reply
#2
If you need to choose rows by condition use loc instead:
df = df.loc[filter_1 & filter_2]
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New Dataframe Column Based on Several Conditions nb1214 1 1,782 Nov-16-2021, 10:52 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020