Skip to content

Commit 3699fcc

Browse files
mushmula27prateekiiest
authored andcommitted
Bird migration (prateekiiest#174)
* Imported required modules and csv data. Added requirements.txt * Commented out the head() calls as they don't need to run in the script. Clarified how they can be used in ipython in the comments * Labelled y-axis * Fixed csv source file URL length issue
1 parent c00dd4c commit 3699fcc

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

Code-Sleep-Python/Bird_migration/code.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
# Import bird data
6+
birddata = pd.read_csv('https://d37djvu3ytnwxt.cloudfront.net/assets/'
7+
'courseware/v1/c72498a54a4513c2eb4ec005adc0010c/'
8+
'asset-v1:HarvardX+PH526x+3T2016+type@asset+block/bird_tracking.csv')
9+
110
# First, use `groupby` to group up the data.
211
grouped_birds = birddata.groupby("bird_name")
312

413
# Now operations are performed on each group.
514
mean_speeds = grouped_birds.speed_2d.mean()
615

716
# The `head` method prints the first 5 lines of each bird.
8-
grouped_birds.head()
17+
# This is useful if you are running this in ipython and need to see some data.
18+
# Call this only on pandas data frame.
19+
# mean_speeds.head()
920

1021
# Find the mean `altitude` for each bird.
1122
# Assign this to `mean_altitudes`.
1223

1324
mean_altitudes = grouped_birds.altitude.mean()
1425

1526

16-
17-
1827
# Convert birddata.date_time to the `pd.datetime` format.
1928
birddata.date_time = pd.to_datetime(birddata.date_time)
2029

2130
# Create a new column of day of observation
2231
birddata["date"] = birddata.date_time.dt.date
2332

24-
# Check the head of the column.
25-
birddata.date.head()
33+
# If you're in ipython and want to check the head of the column run:
34+
# birddata.date.head()
2635

2736
grouped_bydates = birddata.groupby("date")
2837
mean_altitudes_perday = grouped_bydates.altitude.mean()
@@ -33,8 +42,8 @@
3342
grouped_birdday = birddata.groupby(["bird_name","date"])
3443
mean_altitudes_perday = grouped_birdday.altitude.mean()
3544

36-
# look at the head of `mean_altitudes_perday`.
37-
mean_altitudes_perday.head()
45+
# If you're in ipython and want to look at the head of `mean_altitudes_perday` run:
46+
# mean_altitudes_perday.head()
3847

3948

4049
grouped_birdday = birddata.groupby(["bird_name","date"])
@@ -48,4 +57,5 @@
4857
sanne_daily_speed.plot(label="Sanne")
4958
nico_daily_speed.plot(label="Nico")
5059
plt.legend(loc="upper left")
60+
plt.ylabel("2D mean speed (m/s)")
5161
plt.show()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cycler==0.10.0
2+
kiwisolver==1.1.0
3+
matplotlib==3.1.1
4+
numpy==1.17.3
5+
pandas==0.25.2
6+
pyparsing==2.4.2
7+
python-dateutil==2.8.0
8+
pytz==2019.3
9+
six==1.12.0

0 commit comments

Comments
 (0)