lan = sns.factorplot('Län', data=df, kind='count', size=8, aspect=2)
lan.set_xticklabels(rotation=45)

"""
Explanation: Simple statistics

Distribution of species per region (Län).
End of explanation
"""


# Show the 10 contributors that contributed the most. (change value of .nlargest() to show more) 
df['Observatör'].value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True).nlargest(10)

"""
Explanation: Contributors
To find out who contributed to the species observation, you can analyse the "Observatör" column.
End of explanation
"""


# A little plot of the contributors
citizenscientists = sns.factorplot('Observatör', data=df, kind='count', size=8, aspect=2)
citizenscientists.set_xticklabels(rotation=45)

"""
Explanation: Rubrik
Testar
jag har fem saker 
1. hej
End of explanation
"""


# Create a new column for the X and Y values, to be converted to latlong below
df['latlong'] = list(zip(df.X, df.Y))

map_1 = folium.Map(location=[62.128, 18.6435], zoom_start=4,
                   tiles='Mapbox Bright')

for index, row in df.iterrows():
    # Transform X,Y to latlong by switching place and replacing comma with dot
    longitude = row['latlong'][1].replace(',', '.')
    latitude = row['latlong'][0].replace(',', '.')
    
    #print(row)
    vet = str(row['Vetenskapligt namn'])
    svnamn = str(row['Svenskt namn']).capitalize()
    observ = str(row['Observatör'])
    lokal = str(row['Lokal'])
    lan = str(row['Län'])
    koord = str(row['Koordinatnoggrannhet (m)'])
    datum = str(row['Startdatum'])
    datakalla = str(row['Datakälla'])
    
    label = str(vet + " - " + svnamn + " | " + observ + " | " + lokal + ", " 
                + lan + " | Koordinatnogrannhet (m): " + koord + " | " + 
                datum + " | " + datakalla + " | Latitud: " 
                + latitude + " | Longitud: " + longitude)
            
    folium.Marker([longitude, latitude], popup=label).add_to(map_1)
    # Add to change colors: icon = folium.Icon(color ='blue')

map_1.save('mardhund.html')
map_1

"""
Explanation: Geographic visualization

Make a new column where the WGS84 columns are formatted properly.
Make a simple map using the folium library.
End of explanation
"""


# Create dataframe with DateTime as index. For time series.
ts = df.set_index(pd.DatetimeIndex(df['Startdatum'])) # Create a dataframe with datetime as index
print(ts.index) # make sure the dtype='datetime64[ns]'
print("Oldest value: " + ts['Startdatum'].min())
print("Newest value: " + ts['Startdatum'].max())

# Plotting time series of the coordinate accuracy. Has no real meaning, just for code. 
ts['Koordinatnoggrannhet (m)'].plot()

ts

"""
Explanation: Time series

Create dataframe with DateTime as index.
Plot some value on time series frame.
End of explanation
"""


