0

So I have a dataframe that looks like this:

import pandas as pd
df = pd.df[index=['2014', '2015', '2016'], columns = ['Latitude', 'Longitude'], data = ['14.0N', '33.0W'],['22.0S', '12.0E']]

I want to go through and check the cells in the longitude column if they have an N or an S.

2 Answers2

2

I will using endswith

df.Longitude.str.endswith(('N','S'))
Out[77]: 
2014    False
2015    False
Name: Longitude, dtype: bool
BENY
  • 258,262
  • 17
  • 121
  • 165
1

Use the following:

# Example data
df = pd.DataFrame(index=['2014', '2015'], 
           columns = ['Latitude', 'Longitude'], 
           data = [['14.0N', '33.0W'],['22.0S', '12.0E']])
print(df)
     Latitude Longitude
2014    14.0N     33.0W
2015    22.0S     12.0E

Check if 'N' or 'S' is in each row of Longitude:

df.Longitude.str.contains('|'.join(['N', 'S']))
2014    False
2015    False
Name: Longitude, dtype: bool
Nathaniel
  • 2,825
  • 6
  • 14