image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/BRAZIL_CITIES.csv', sep=';', decimal=',')

df.fillna(0.0, inplace=True)

mask1 = df['LONG'] != 0
mask2 = df['LAT'] != 0
mask3 = df['CAPITAL'] == 1

mask1 = df['LONG'] != 0
mask2 = df['LAT'] != 0
mask3 = df['CAPITAL'] == 1
scale_factor = 20000

avg_growth = (df['ESTIMATED_POP'].sum() - df['IBGE_RES_POP'].sum()) / df['IBGE_RES_POP'].sum() * 100

pop_by_state = df[['STATE', 'ESTIMATED_POP']].groupby(by='STATE').sum().sort_values(by='ESTIMATED_POP', ascending=False)

fastest_growing_states = df[['STATE', 'IBGE_RES_POP', 'ESTIMATED_POP']].groupby(by='STATE').sum()
fastest_growing_states['%GROWTH'] = (fastest_growing_states['ESTIMATED_POP'] - fastest_growing_states['IBGE_RES_POP']) / fastest_growing_states['IBGE_RES_POP'] * 100
fgs = fastest_growing_states.sort_values(by='%GROWTH', ascending=False)
plt.figure(figsize=(15, 10))
plt.bar(fgs.index, fgs['%GROWTH'], label='% growth')
plt.plot(fgs.index, [avg_growth] * fgs.index.shape[0], color='red', label='% avg growth')
plt.legend()
plt.title('Fastest growing states')
plt.show()