image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

df = pd.read_csv('../input/all_energy_statistics.csv')
df.columns = ['country', 'commodity', 'year', 'unit', 'quantity', 'footnotes', 'category']

df_solar = df[df.commodity.str.contains('Electricity - total net installed capacity of electric power plants, solar')]
df_max = df_solar.groupby(pd.Grouper(key='country'))['quantity'].max()
df_max = df_max.sort_values(ascending=False)
df_max = df_max[:6]
df_max.index.values

commodity_string = 'Electricity - total net installed capacity of electric power plants, solar'
df_max = df[df.commodity.str.contains(commodity_string)].groupby(pd.Grouper(key='country'))['quantity'].max().sort_values(ascending=False)[:6]
range = np.arange(2000, 2015)
dict_major = {}
for c in df_max.index.values:
    read_index = df_solar[df_solar.commodity.str.contains(commodity_string) & df_solar.country.str.contains(c + '$')].year
    read_data = df_solar[df_solar.commodity.str.contains(commodity_string) & df_solar.country.str.contains(c + '$')].quantity
    read_data.index = read_index
    prod = read_data.reindex(index=range, fill_value=0)
    dict_major.update({c: prod.values})
df_major = pd.DataFrame(dict_major)
df_major.index = range
df_major

ax = df_major.plot(kind='bar', x=df_major.index, stacked=False, figsize=(15, 9))
plt.title('Solar energy production')
plt.xlabel('Year')
plt.ylabel('Megawatts')
ax.yaxis.grid(False, 'minor')
ax.yaxis.grid(True, 'major')