You are on page 1of 7

9/26/2020 Jupyter Notebook Viewer

Course-work-and-data-analysis (/github/bikasbhattarai/Course-work-and-data-analysis/tree/master)
/
Hydrology-Course (/github/bikasbhattarai/Course-work-and-data-analysis/tree/master/Hydrology-Course)
/
GEO2010 (/github/bikasbhattarai/Course-work-and-data-analysis/tree/master/Hydrology-Course/GEO2010)
/
EX0 (/github/bikasbhattarai/Course-work-and-data-analysis/tree/master/Hydrology-Course/GEO2010/EX0)

GEO 2010 Surface Hydrology

Spring 2017

Exercise 1

Date: 2017-01-16

The main objectives of this exercise are:

1. Read the data from different file format ( e.g .txt, .csv,.xlsx,.dat
ect)
2. data presentation and visualization
3. handling of large datasets

Software liberary that we are going to use:

For data manipulating and analysis:

1. Pandas
2. Numpy

for data visualization:

1. matplotlib (plotting library)

Task 1
In [117]:

# Import liberary/ modules


%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 1/7
9/26/2020 Jupyter Notebook Viewer

Plot your data (line plot for temperature and discharge, bar plot for precipitation and pi chart for global
water distribution)

1. precipitation data is given in .txt file


2. discharge data with monthly average precipitation is given in .xlsx file
3. temperature data is given in .csv file
4. global water distribution is given in .csv file

In [213]:

# use panda to read data from .csv file

#data = pd.read_table('filename.csv',sep = ',')


data = pd.read_table('/home/bikas/Desktop/ex1_goe2010/prec.txt',sep = ',')
data['Date'] = pd.to_datetime(data['Date'])
plt.plot(data['Date'],data['Daily_Precip(mm)'])
plt.xlabel('Years')
plt.ylabel('Precipitation (mm)')
plt.title('Daily Precipitation at Station A')
plt.show()

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 2/7
9/26/2020 Jupyter Notebook Viewer

In [228]:

# plot for temperature


temp = pd.read_table('/home/bikas/Desktop/ex1_goe2010/temp.csv',sep = ',')
temp['Date'] = pd.to_datetime(temp['Date'])
plt.plot(temp['Date'],temp['Daily Mean Temperature (oC)'],'r')
plt.xlabel('Years')
plt.ylabel('Daily average temp (0c)')
plt.title('Average daily temperature at Station A')
plt.show()

In [225]:

# discharge plot
discharge = pd.ExcelFile('/home/bikas/Desktop/ex1_goe2010/discharge.xlsx')
#discharge.sheet_names
df_dis = discharge.parse("87-00")
plt.plot(df_dis['Date'],df_dis['Daily_discharge(m3/s)'],'g')
plt.xlabel('Years')
plt.ylabel('Discharge m3/s')
plt.title('Daily discharge at station A')
plt.show()

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 3/7
9/26/2020 Jupyter Notebook Viewer

In [214]:

# plot bar graph


df_av_pre = discharge.parse('Sheet4')
x= np.arange(12)
month = (df_av_pre.Month)
plt.bar(x,df_av_pre['avg_ppt'])
plt.xticks(x,month)
plt.xlabel('Month')
plt.ylabel('Avearge Monthly total precipitation (mm) ')
plt.title('Average Monthly total precipitation at station A ')
plt.show()

In [ ]:

# to read data from csv and .txt file use panda for eg:
# df = pd.read_table('filename',sep = ',')

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 4/7
9/26/2020 Jupyter Notebook Viewer

In [215]:

# Create a pie chart


df = pd.read_table('/home/bikas/Desktop/ex1_goe2010/global_water.csv',sep =',')
plt.pie(df['percentage'],labels=df['Water source'],shadow=False,)
#View the plot drop above
plt.axis('equal')
# View the plot
plt.tight_layout()
plt.title ('Global distribution of Water')
plt.show()

Obligatory Exericise:
In [227]:

#Question no.1:

In [253]:

df_temp = (temp.set_index(temp['Date'])).drop('Date',axis =1)

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 5/7
9/26/2020 Jupyter Notebook Viewer

In [251]:

(df_temp.resample('m').mean()).plot()

Out[251]:

<matplotlib.axes._subplots.AxesSubplot at 0x7f58bde225c0>

In [250]:

(df_temp.resample('A').mean()).plot()

Out[250]:

<matplotlib.axes._subplots.AxesSubplot at 0x7f58bdf08fd0>

In [256]:

# warmest month

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 6/7
9/26/2020 Jupyter Notebook Viewer

In [257]:

mon_temp = df_temp.resample('m').mean()
mon_temp.max()

Out[257]:

Daily Mean Temperature (oC) 10.809677


dtype: float64

In [258]:

mon_temp.idxmax()

Out[258]:

Daily Mean Temperature (oC) 1997-07-31


dtype: datetime64[ns]

In [ ]:

https://nbviewer.jupyter.org/github/bikasbhattarai/Course-work-and-data-analysis/blob/master/Hydrology-Course/GEO2010/EX0/… 7/7

You might also like