phrayth23
phrayth23

Reputation: 23

Display another column where the conditions are determined in other columns

address latitude longitude
Tokyo 124.4423 95.223
Budapest 156.2442 78.112
Perth 124.9234 20.490

I have an example of a data frame as seen above (please don't mind the accuracy); address is string, latitude and longitude are floats. I would like to to display the address where the condition meets both latitude and longitude.

Example:

Latitude = 156.2442
Longitude = 78.112

Therefore I want to display/print the corresponding column address, which would be "Budapest".

Upvotes: 2

Views: 79

Answers (2)

Mohammad Talaei
Mohammad Talaei

Reputation: 437

You can use Pandas filtering:

df[(df.latitude=='156.2442') & (df.longitude == '78.112')]['address']

Upvotes: 1

sophocles
sophocles

Reputation: 13831

One approach you can take is:

lat = 156.2442 # insert your latitude
long = 78.112 # insert your longtitude
print(df[(df['latitude']==lat) & (df['longitude'] == long)]['address'])

which prints:

1    Budapest
Name: address, dtype: object

Upvotes: 1

Related Questions