In [2]:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

In [3]:
data=pd.read_csv("05_temp_rain_v2.csv")
#data.columns
#data

In [4]:
pivot=data.pivot_table(["rain(mm)","temp(dC)"], index=["loc","month"])#.plot()
pivot.head()


Out[4]:
rain(mm) temp(dC)
loc month
Adria_-_Bellombra 1 41.314286 2.933333
2 41.552381 4.280952
3 49.152381 8.733333
4 60.342857 13.038095
5 67.590476 18.185714

In [5]:
pivot=data.pivot_table(["rain(mm)","temp(dC)"], index=["loc","month"])#.plot()
pivot

#pivot.xs("Agna", level=0)
locations=pivot.index.get_level_values(0).unique()
print(locations)
months=pivot.index.get_level_values(1).unique()
print(months)

for location in locations:
    #print(pivot.xs(location, level=0))
    split=pivot.xs(location)
    print(split)
    #split.plot()
    #break
    rain=list(split["rain(mm)"])#.plot(kind="bar")
    temp=split(["temp(dC)"])#.plot()
    print("printing rain")
    print(list(rain))
    print("printing temp")
    print(list(temp))    
    #rain.plot(kind="bar")
    #temp.plot()
    
    i = np.arange(len(rain))
    fig, rr = plt.subplots()

    #bar_width = 1

    opacity = 0.4
    #error_config = {'ecolor': '0.3'}


    rr.bar(i, rain, alpha=opacity, color='b',
                  align='center' )

    tt=plt.twinx()
    tt.plot(temp, linestyle='-', color="r", linewidth=1.0, label="temp")

    plt.xlabel('months')
    rr.set_ylabel('(mm)')
    #plt.ylabel('(mm)')
    tt.set_ylabel('(C)')
    text="rain and temp of " + location
    plt.title(text)
    plt.xticks(i,('jan', 'feb', 'mar', 'apr', 'mai', 'jun', 'jul', 'aug', 'sept', 'oct', 'nov', 'dez'))
    plt.legend()
    plt.grid(True)


    rr.set_ylim([0,40])
    plt.tight_layout()
    plt.show()
    break
        
    #rain=pivot.xs(location, level=0)["rain(mm)"]
    #temp=pivot.xs(location, level=0)["temp(dC)"]
    #print(rain)
    #rain.plot(kind="bar")
    #temp.plot()
    #plt.show()


['Adria_-_Bellombra' 'Agna' 'Agordo']
[ 1  2  3  4  5  6  7  8  9 10 11 12]
        rain(mm)   temp(dC)
month                      
1      41.314286   2.933333
2      41.552381   4.280952
3      49.152381   8.733333
4      60.342857  13.038095
5      67.590476  18.185714
6      63.828571  21.704762
7      50.085714  23.485714
8      58.809524  23.185714
9      73.076190  18.823810
10     77.047619  14.228571
11     71.009524   8.828571
12     54.780952   3.733333
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-607d3e4cd743> in <module>()
     15     #break
     16     rain=list(split["rain(mm)"])#.plot(kind="bar")
---> 17     temp=split(["temp(dC)"])#.plot()
     18     print("printing rain")
     19     print(list(rain))

TypeError: 'DataFrame' object is not callable