0
'x = df.loc[df['City'].isnull()] & df.loc[df['Latitude']== 0]'

The error message is "unsupported operand type(s) for |: 'float' and 'bool'"

x = df.loc[df['City'].isnull()] and df.loc[df['Latitude']== 0]

The error message is "The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()"

how I can multiple conditions on Dataframe then remove these rows? Thank you

  • Take the error message "Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()", paste it into a google search and start going through the results, it is faster – cs95 Dec 13 '19 at 18:57

1 Answers1

0

I think you are missing some parenthesys and an extra df. This should work I think:

x = df[(df['City'].isnull()) & (df['Latitude'] != 0)]

However if you wish to filter the rows that do not match this criteria, you can simply use:

x = df[(~df['City'].isnull()) & (df['Latitude'] != 0)]

Example:

import pandas as pd
import numpy as np
data = {'City':['some_text','more_text',np.nan],'Latitude':[0,1,0]}
df = pd.DataFrame(data)
df_filtered = df[(df['City'].isnull()) & (df['Latitude'] == 0)]
print(df_filtered) 

Output:

  City  Latitude
2  NaN         0

Output for second case:

        City  Latitude
1  more_text         1
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53