Skip to content

This is cool. Add it as a fxn. #12

@coffeefilter77

Description

@coffeefilter77

Input:
ireland_ekg =

   EKG_ID COUNTRY_CODE NUTS_ID NUTS_NAME  POP_WEIGHT                          GEOMETRY
0  2454985           IE   IE041    Border   33.168070    POINT (-7.283224391 55.052073)
1  2454986           IE   IE041    Border    0.000000  POINT (-7.797808823 54.72021103)
2  2454987           IE   IE041    Border    1.009893  POINT (-7.914663605 54.69390413)
3  2454988           IE   IE041    Border   23.762199  POINT (-7.567322558 54.74429863)
4  2454989           IE   IE041    Border   17.197892   POINT (-7.75988053 54.70726282)

Use this:

# Extract latitude and longitude from the 'GEOMETRY' column
def extract_coordinates(point_str):
    match = re.findall(r'-?\d+\.\d+', point_str)
    return tuple(map(float, match))

ireland_ekg['lat'], ireland_ekg['long'] = zip(*ireland_ekg['GEOMETRY'].apply(extract_coordinates))

to get:

 EKG_ID COUNTRY_CODE NUTS_ID NUTS_NAME  POP_WEIGHT       lat       long
0      2454985           IE   IE041    Border   33.168070 -7.283224  55.052073
1      2454986           IE   IE041    Border    0.000000 -7.797809  54.720211
2      2454987           IE   IE041    Border    1.009893 -7.914664  54.693904
3      2454988           IE   IE041    Border   23.762199 -7.567323  54.744299

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions