0

I'm using pandas and I want to filter on a column for values value_1, value_2, and blanks. In excel I can select filter go to the column and select value_1, value_2, and blanks but in pandas its only returning value_1 and value_2. Ultimately, I want to fill in the blanks with a value of value_1 but I need to get to the point where I have a dataframe and a series that has value_1, value_2, and blanks (empty columns)

    example Data {'country': ['United States of America', 'Canada', 'Argentina', ' ']}

    import pandas as pd
    file='countries.xlsx'
    df=pd.read_excel(file)
    US_CA_Blanks=['Canada', 'United States of America', 'Argentina', '(Blanks)', '', ' 
    ','Blanks']
    df_US_CA_Blanks_col_B.country.isin(US_CA_Blanks_col_B)

and this returns only US, CA, Argentina but not the blanks. I have also tried to put on the list a variety of spaces and quotes examples above with no luck.

John
  • 125
  • 2
  • 10

1 Answers1

0

try this syntax:

df[(df["column_name"] == "condition1") | (df["column_name"] == "condition2")]

chacobsa
  • 11
  • 1
  • I tried and it did not filter and it returned everything. Thank you for the comment! – John Feb 24 '23 at 11:32
  • I found the actual answer here on this post https://stackoverflow.com/questions/70127062/filter-pandas-dataframe-by-a-list-that-includes-an-empty-values#:~:text=Pandas%20has%20a%20build-in%20function%20called%20isnull%20%28%29,False%2C%20axis%3D1%29%20empty_df%20%3D%20df%20%5Bboolean_series%5D%20return%20empty_df – John Feb 24 '23 at 16:11