Workspace
Ronit Kumar Purohit/

My workspace

0
Beta
Spinner

Exploring the Evolution of Pollution: A Visual EDA of Emissions Over the Years

Hidden code
Hidden code
Hidden code
# Display the first few rows of the dataset
print(df.head())

# Check the columns in the dataset
print(df.columns)

# Get basic statistics of the numerical columns
print(df.describe())
# Sort the DataFrame by total CO2 emissions in descending order
df_sorted = df.groupby('country')['consumption_co2'].sum().sort_values(ascending=False)

# Select the top 30 countries by total CO2 emissions
top_30_countries = df_sorted.head(30).index.tolist()

# Include the 'World' data in the selected countries
top_30_countries.append('World')

# Filter the DataFrame to include rows of the top 30 countries and the 'World'
df_filtered = df[df['country'].isin(top_30_countries)]

# Print the filtered DataFrame
print(df_filtered)
# Extract the dataframe to a csv file named 'CO2_VIZ.csv'
df_filtered.to_csv('CO2_VIZ.csv', index=False)
# Exclude countries with 0 in 'consumption_co2'
df_filtered = df_filtered[df_filtered['consumption_co2'] != 0]

df_filtered