import numpy as np, pandas as pd, json from pygeocoder import Geocoder import matplotlib.pyplot as plt %matplotlib inline df=pd.read_excel('http://www.recensamantromania.ro/wp-content/uploads/2013/07/sR_TAB_13.xls') megye=[] for i in df.index[6:3434]: try: if np.isnan(df.ix[int(i)-1,u'13. POPULATIA STABILA DUPA RELIGIE - JUDETE, MUNICIPII, ORASE, COMUNE']) and\ np.isnan(df.ix[int(i)+1,u'13. POPULATIA STABILA DUPA RELIGIE - JUDETE, MUNICIPII, ORASE, COMUNE']): megye.append([i,df.ix[i,u'13. POPULATIA STABILA DUPA RELIGIE - JUDETE, MUNICIPII, ORASE, COMUNE']]) except: pass #run once only! df=df.drop([u'Unnamed: 1',u'Unnamed: 24'],axis=1) df.columns=[u'Falu',u'Ortodox',u'Katolikus',u'Református',u'Pünkösdista',u'Görög katolikus',u'Baptista',u'Adventista',u'Muzulmán',u'Unitárius',u'Jehova tanúja',u'Lutheránus evangélikus',u'Ókatolikus',u'Lutheránus',u'Szerb ortodox',u'Evangélikus',u'Kálvinista',u'Zsidó',u'Örmény',u'Más',u'Nem vallásos',u'Ateista',u'N/A'] df=df.drop(u'N/A',axis=1) #run once only! df=df.loc[df.index[7:]] data={} data2={} data3={} ez=0 for i in df.index: try: if megye[ez][0]