Air Pollution in Manila

Air Pollution in Manila#

# Function to convert JSON strings to Polygon objects
def create_polygon(geo_json):
    geo_dict = json.loads(geo_json)
    if geo_dict['type'] == 'Polygon':
        return Polygon(geo_dict['coordinates'][0])

# Apply the function to the 'geo' column to create a new 'geometry' column
air_pollution['geometry'] = air_pollution['geo'].apply(create_polygon)

# Convert the DataFrame to a GeoDataFrame
gdf = gpd.GeoDataFrame(air_pollution, geometry='geometry')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[1], line 8
      5         return Polygon(geo_dict['coordinates'][0])
      7 # Apply the function to the 'geo' column to create a new 'geometry' column
----> 8 air_pollution['geometry'] = air_pollution['geo'].apply(create_polygon)
     10 # Convert the DataFrame to a GeoDataFrame
     11 gdf = gpd.GeoDataFrame(air_pollution, geometry='geometry')

NameError: name 'air_pollution' is not defined
air_pollution[['adm4_en', 'O3_column_number_density', 'date']].set_index(['date']).plot()
<Axes: xlabel='date'>
../../_images/fc4f9846d46d85bef5ac66ae63aebcd57c77f905805632abca621115cd2ca701.png
air_pollution.to_csv('../../data/air_pollution/monthly_o3_2022-2023.csv')