Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
python-uga
py-training-2017
Commits
eaba0705
Commit
eaba0705
authored
Feb 27, 2019
by
Loic Huder
Browse files
Added multiple choices for step 1
parent
f53b9a93
Changes
1
Hide whitespace changes
Inline
Side-by-side
ipynb/pres09_practical1.ipynb
View file @
eaba0705
...
...
@@ -40,34 +40,38 @@
The temperature measurement is in kelvin (273,15 K $
\l
eftrightarrow$ 0 °C)
%% Cell type:markdown id: tags:
# Step
1.
1: load data
# Step 1: load data
Write a script with a function
`load_data()`
that
-
open the file
-
load data in a dictionary (global variable) with these structure
```
python
{
'Date'
:
[
wind
,
temperature
,
humidity
,
rainfall
]}
```
For example
```
python
{
'2016-01-01T01'
:
[
2.0
,
283.75
,
94
,
0.2
],
'2016-01-01T04'
:
[
2.2
,
283.95
,
91
,
0.2
]
}
```
-
load data in one of the following structures (more details below):
-
1.1 Single dictionnary
-
1.2 Multiple structures
-
1.3 Class instance (object-oriented)
## 1.1: Single dictionnary (pres07)
Load in the data in a single dictionnary of this structure:
```
python
{
'Date'
:
[
wind
,
temperature
,
humidity
,
rainfall
]}
```
For example
```
python
{
'2016-01-01T01'
:
[
2.0
,
283.75
,
94
,
0.2
],
'2016-01-01T04'
:
[
2.2
,
283.95
,
91
,
0.2
]
}
```
In this case, we can consider YYYY-MM-DDTHH as the key for the station dictionary.
Split each line and extract data.
##
h
int
##
##
H
int
You can use the method
*split*
from the str class.
%% Cell type:code id: tags:
...
...
@@ -77,47 +81,75 @@
print
(
l
)
```
%% Cell type:markdown id: tags:
# Step 1.2: Compute max temperature and average temperature for the station
## 1.2: Multiple structures (pres07)
Load the data in multiple dictionnaries or lists (one per field).
#### Example for dictionnaries:
You can use the following structure
```
python3
wind = {'Date1': wind_value1, 'Date2: wind_value2, ...}
temperature = {'Date1': temperature1, 'Date2: temperature2, ...}
...
```
#### Example for lists:
You can use the following structure
```
python3
dates = ['Date1', 'Date2', ...]
wind = [wind_value1, wind_value2, ...]
temperature = [temperature1, temperature2, ...]
...
```
%% Cell type:markdown id: tags:
## 1.3: Class instance (pres08)
Load the data in an instance of a class
`WeatherStation`
that you will define yourself.
`load_data()`
can therefore be a method of this class.
#### Hint :
This is very similar as 1.2. The only difference is that the structures storing the data are attributes of a class.
%% Cell type:markdown id: tags:
# Step 2: Compute max temperature and average temperature for the station
Write 2 functions
`get_max_temperature()`
and
`get_average_temperature()`
that:
-
return a float
%% Cell type:markdown id: tags:
# Step
1.
3: Compute sum of the rainfall for one station
# Step 3: Compute sum of the rainfall for one station
Write 1 function
`get_sum_rainfall()`
that sum the rainfall.
-
return a float
Be careful, some measurement have no rainfall data.
%% Cell type:markdown id: tags:
# Step
1.
4: Search max period without rainfall
# Step 4: Search max period without rainfall
Write 1 function
`period_without_rainfall()`
-
return the beginning date, the ending date and the number of days without rainfall
## Hint
This is the syntax to return m
ore than 1
value in a function:
This is the syntax to return m
ultiple
value
s
in a function:
```
return date_min, date_max, period_max / 8
```
%% Cell type:markdown id: tags:
# Step
1.
5: How many hours with humidity rate < 60
# Step 5: How many hours with humidity rate < 60
Write 1 function
`get_hours_humidity(rate)`
-
takes 1 parameter : the humidity rate
-
returns the number of days
...
...
@@ -132,11 +164,11 @@
%% Cell type:code id: tags:
```
python
import
pandas
df
=
pandas
.
read_
table
(
df
=
pandas
.
read_
csv
(
'../TP/TP1_MeteoData/data/synop-2016.csv'
,
sep
=
','
,
header
=
0
)
# print(df.columns)
# print(df.age)
# print(df['Temperature'])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment