Pandas Exercise 6 : Stats
The continuity of my practice on Pandas exercise from guisapmora.
US - Baby Names Dataset
Introduction:
We are going to use a subset of US Baby Names from Kaggle.
In the file it will be names from 2004 until 2014
Step 1. Import the necessary libraries
import pandas as pd
Step 2. Import the dataset from this address.
Step 3. Assign it to a variable called baby_names.
url = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/06_Stats/US_Baby_Names/US_Baby_Names_right.csv'
baby_name = pd.read_csv(url)
Step 4. See the first 10 entries
baby_name.head(10)
Unnamed: 0 | Id | Name | Year | Gender | State | Count | |
---|---|---|---|---|---|---|---|
0 | 11349 | 11350 | Emma | 2004 | F | AK | 62 |
1 | 11350 | 11351 | Madison | 2004 | F | AK | 48 |
2 | 11351 | 11352 | Hannah | 2004 | F | AK | 46 |
3 | 11352 | 11353 | Grace | 2004 | F | AK | 44 |
4 | 11353 | 11354 | Emily | 2004 | F | AK | 41 |
5 | 11354 | 11355 | Abigail | 2004 | F | AK | 37 |
6 | 11355 | 11356 | Olivia | 2004 | F | AK | 33 |
7 | 11356 | 11357 | Isabella | 2004 | F | AK | 30 |
8 | 11357 | 11358 | Alyssa | 2004 | F | AK | 29 |
9 | 11358 | 11359 | Sophia | 2004 | F | AK | 28 |
Step 5. Delete the column ‘Unnamed: 0’ and ‘Id’
baby_name = baby_name.drop(columns=['Unnamed: 0', 'Id'], axis=1)
Step 6. Is there more male or female names in the dataset?
baby_name['Gender'].value_counts()
F 558846
M 457549
Name: Gender, dtype: int64
Step 7. Group the dataset by name and assign to names
names = baby_name.groupby(['Name']).count()
Step 8. How many different names exist in the dataset?
names.shape[0]
17632
Step 9. What is the name with most occurrences?
names['Count'].sort_values(ascending=False).head(1)
Name
Riley 1112
Name: Count, dtype: int64
Step 10. How many different names have the least occurrences?
names[names['Count'] == names['Count'].min()].shape[0]
3682
Step 11. What is the median name occurrence?
names['Count'].median()
8.0
Step 12. What is the standard deviation of names?
names['Count'].std()
122.02996350814125
Step 13. Get a summary with the mean, min, max, std and quartiles.
names['Count'].describe()
count 17632.000000
mean 57.644907
std 122.029964
min 1.000000
25% 2.000000
50% 8.000000
75% 39.000000
max 1112.000000
Name: Count, dtype: float64
Wind Statistics Dateset
Introduction:
The data have been modified to contain some missing values, identified by NaN.
Using pandas should make this exercise
easier, in particular for the bonus question.
You should be able to perform all of these operations without using a for loop or other looping construct.
- The data in ‘wind.data’ has the following format:
"""
Yr Mo Dy RPT VAL ROS KIL SHA BIR DUB CLA MUL CLO BEL MAL
61 1 1 15.04 14.96 13.17 9.29 NaN 9.87 13.67 10.25 10.83 12.58 18.50 15.04
61 1 2 14.71 NaN 10.83 6.50 12.62 7.67 11.50 10.04 9.79 9.67 17.54 13.83
61 1 3 18.50 16.88 12.33 10.13 11.17 6.17 11.25 NaN 8.50 7.67 12.75 12.71
"""
'\nYr Mo Dy RPT VAL ROS KIL SHA BIR DUB CLA MUL CLO BEL MAL\n61 1 1 15.04 14.96 13.17 9.29 NaN 9.87 13.67 10.25 10.83 12.58 18.50 15.04\n61 1 2 14.71 NaN 10.83 6.50 12.62 7.67 11.50 10.04 9.79 9.67 17.54 13.83\n61 1 3 18.50 16.88 12.33 10.13 11.17 6.17 11.25 NaN 8.50 7.67 12.75 12.71\n'
The first three columns are year, month and day. The remaining 12 columns are average windspeeds in knots at 12 locations in Ireland on that day.
More information about the dataset go here.
Step 1. Import the necessary libraries
import pandas as pd
Step 2. Import the dataset from this address
Step 3. Assign it to a variable called data and replace the first 3 columns by a proper datetime index.
url = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/06_Stats/Wind_Stats/wind.data'
data = pd.read_csv(url, sep='\s+', parse_dates=[0,1,2])
Step 4. Year 2061? Do we really have data from this year? Create a function to fix it and apply it.
data['Yr'] = data['Yr'].apply(lambda x : '19' + x)
Step 5. Set the right dates as the index. Pay attention at the data type, it should be datetime64[ns].
data.set_index(pd.to_datetime(data['Yr']+data['Mo']+data['Dy'], format='%Y%m%d'), inplace=True)
data.drop(columns=['Yr', 'Mo', 'Dy'], axis=1, inplace=True)
Step 6. Compute how many values are missing for each location over the entire record.
They should be ignored in all calculations below.
data.isna().sum()
RPT 6
VAL 3
ROS 2
KIL 5
SHA 2
BIR 0
DUB 3
CLA 2
MUL 3
CLO 1
BEL 0
MAL 4
dtype: int64
Step 7. Compute how many non-missing values there are in total.
(data.count() - data.isna().sum()).sum()
78826
Step 8. Calculate the mean windspeeds of the windspeeds over all the locations and all the times.
A single number for the entire dataset.
data.mean().mean()
10.227982360836924
Step 9. Create a DataFrame called loc_stats and calculate the min, max and mean windspeeds and standard deviations of the windspeeds at each location over all the days
A different set of numbers for each location.
loc_stats = pd.DataFrame(data.describe()).T
loc_stats
count | mean | std | min | 25% | 50% | 75% | max | |
---|---|---|---|---|---|---|---|---|
RPT | 6568.0 | 12.362987 | 5.618413 | 0.67 | 8.12 | 11.71 | 15.92 | 35.80 |
VAL | 6571.0 | 10.644314 | 5.267356 | 0.21 | 6.67 | 10.17 | 14.04 | 33.37 |
ROS | 6572.0 | 11.660526 | 5.008450 | 1.50 | 8.00 | 10.92 | 14.67 | 33.84 |
KIL | 6569.0 | 6.306468 | 3.605811 | 0.00 | 3.58 | 5.75 | 8.42 | 28.46 |
SHA | 6572.0 | 10.455834 | 4.936125 | 0.13 | 6.75 | 9.96 | 13.54 | 37.54 |
BIR | 6574.0 | 7.092254 | 3.968683 | 0.00 | 4.00 | 6.83 | 9.67 | 26.16 |
DUB | 6571.0 | 9.797343 | 4.977555 | 0.00 | 6.00 | 9.21 | 12.96 | 30.37 |
CLA | 6572.0 | 8.495053 | 4.499449 | 0.00 | 5.09 | 8.08 | 11.42 | 31.08 |
MUL | 6571.0 | 8.493590 | 4.166872 | 0.00 | 5.37 | 8.17 | 11.19 | 25.88 |
CLO | 6573.0 | 8.707332 | 4.503954 | 0.04 | 5.33 | 8.29 | 11.63 | 28.21 |
BEL | 6574.0 | 13.121007 | 5.835037 | 0.13 | 8.71 | 12.50 | 16.88 | 42.38 |
MAL | 6570.0 | 15.599079 | 6.699794 | 0.67 | 10.71 | 15.00 | 19.83 | 42.54 |
Step 10. Create a DataFrame called day_stats and calculate the min, max and mean windspeed and standard deviations of the windspeeds across all the locations at each day.
A different set of numbers for each day.
day_stats = pd.DataFrame(data.T.describe().T)
day_stats
count | mean | std | min | 25% | 50% | 75% | max | |
---|---|---|---|---|---|---|---|---|
1961-01-01 | 11.0 | 13.018182 | 2.808875 | 9.29 | 10.5400 | 13.170 | 15.0000 | 18.50 |
1961-01-02 | 11.0 | 11.336364 | 3.188994 | 6.50 | 9.7300 | 10.830 | 13.2250 | 17.54 |
1961-01-03 | 11.0 | 11.641818 | 3.681912 | 6.17 | 9.3150 | 11.250 | 12.7300 | 18.50 |
1961-01-04 | 12.0 | 6.619167 | 3.198126 | 1.79 | 4.5700 | 5.855 | 9.1175 | 11.75 |
1961-01-05 | 12.0 | 10.630000 | 2.445356 | 6.17 | 9.8075 | 11.170 | 12.1700 | 13.33 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
1978-12-27 | 12.0 | 16.708333 | 7.868076 | 8.08 | 13.8025 | 15.025 | 17.3025 | 40.08 |
1978-12-28 | 12.0 | 15.150000 | 9.687857 | 5.00 | 9.0950 | 13.895 | 16.7000 | 41.46 |
1978-12-29 | 12.0 | 14.890000 | 5.756836 | 8.71 | 10.4775 | 14.210 | 17.0350 | 29.58 |
1978-12-30 | 12.0 | 15.367500 | 5.540437 | 9.13 | 12.3750 | 13.455 | 18.1850 | 28.79 |
1978-12-31 | 12.0 | 15.402500 | 5.702483 | 9.59 | 11.5300 | 12.080 | 19.5200 | 27.29 |
6574 rows × 8 columns
Step 11. Find the average windspeed in January for each location.
Treat January 1961 and January 1962 both as January.
data[data.index.month == 1].mean()
RPT 14.407735
VAL 12.362146
ROS 13.290470
KIL 6.926239
SHA 11.205064
BIR 7.827393
DUB 11.953120
CLA 9.377511
MUL 9.469915
CLO 9.880812
BEL 14.582350
MAL 18.332051
dtype: float64
Step 12. Downsample the record to a yearly frequency for each location.
data.groupby(data.index.year).mean()
RPT | VAL | ROS | KIL | SHA | BIR | DUB | CLA | MUL | CLO | BEL | MAL | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1961 | 12.299583 | 10.351796 | 11.362369 | 6.958227 | 10.881763 | 7.729726 | 9.733923 | 8.858788 | 8.647652 | 9.835577 | 13.502795 | 13.680773 |
1962 | 12.246923 | 10.110438 | 11.732712 | 6.960440 | 10.657918 | 7.393068 | 11.020712 | 8.793753 | 8.316822 | 9.676247 | 12.930685 | 14.323956 |
1963 | 12.813452 | 10.836986 | 12.541151 | 7.330055 | 11.724110 | 8.434712 | 11.075699 | 10.336548 | 8.903589 | 10.224438 | 13.638877 | 14.999014 |
1964 | 12.363661 | 10.920164 | 12.104372 | 6.787787 | 11.454481 | 7.570874 | 10.259153 | 9.467350 | 7.789016 | 10.207951 | 13.740546 | 14.910301 |
1965 | 12.451370 | 11.075534 | 11.848767 | 6.858466 | 11.024795 | 7.478110 | 10.618712 | 8.879918 | 7.907425 | 9.918082 | 12.964247 | 15.591644 |
1966 | 13.461973 | 11.557205 | 12.020630 | 7.345726 | 11.805041 | 7.793671 | 10.579808 | 8.835096 | 8.514438 | 9.768959 | 14.265836 | 16.307260 |
1967 | 12.737151 | 10.990986 | 11.739397 | 7.143425 | 11.630740 | 7.368164 | 10.652027 | 9.325616 | 8.645014 | 9.547425 | 14.774548 | 17.135945 |
1968 | 11.835628 | 10.468197 | 11.409754 | 6.477678 | 10.760765 | 6.067322 | 8.859180 | 8.255519 | 7.224945 | 7.832978 | 12.808634 | 15.017486 |
1969 | 11.166356 | 9.723699 | 10.902000 | 5.767973 | 9.873918 | 6.189973 | 8.564493 | 7.711397 | 7.924521 | 7.754384 | 12.621233 | 15.762904 |
1970 | 12.600329 | 10.726932 | 11.730247 | 6.217178 | 10.567370 | 7.609452 | 9.609890 | 8.334630 | 9.297616 | 8.289808 | 13.183644 | 16.456027 |
1971 | 11.273123 | 9.095178 | 11.088329 | 5.241507 | 9.440329 | 6.097151 | 8.385890 | 6.757315 | 7.915370 | 7.229753 | 12.208932 | 15.025233 |
1972 | 12.463962 | 10.561311 | 12.058333 | 5.929699 | 9.430410 | 6.358825 | 9.704508 | 7.680792 | 8.357295 | 7.515273 | 12.727377 | 15.028716 |
1973 | 11.828466 | 10.680493 | 10.680493 | 5.547863 | 9.640877 | 6.548740 | 8.482110 | 7.614274 | 8.245534 | 7.812411 | 12.169699 | 15.441096 |
1974 | 13.643096 | 11.811781 | 12.336356 | 6.427041 | 11.110986 | 6.809781 | 10.084603 | 9.896986 | 9.331753 | 8.736356 | 13.252959 | 16.947671 |
1975 | 12.008575 | 10.293836 | 11.564712 | 5.269096 | 9.190082 | 5.668521 | 8.562603 | 7.843836 | 8.797945 | 7.382822 | 12.631671 | 15.307863 |
1976 | 11.737842 | 10.203115 | 10.761230 | 5.109426 | 8.846339 | 6.311038 | 9.149126 | 7.146202 | 8.883716 | 7.883087 | 12.332377 | 15.471448 |
1977 | 13.099616 | 11.144493 | 12.627836 | 6.073945 | 10.003836 | 8.586438 | 11.523205 | 8.378384 | 9.098192 | 8.821616 | 13.459068 | 16.590849 |
1978 | 12.504356 | 11.044274 | 11.380000 | 6.082356 | 10.167233 | 7.650658 | 9.489342 | 8.800466 | 9.089753 | 8.301699 | 12.967397 | 16.771370 |
Step 13. Downsample the record to a monthly frequency for each location.
data.groupby(data.index.month).mean()
RPT | VAL | ROS | KIL | SHA | BIR | DUB | CLA | MUL | CLO | BEL | MAL | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 14.407735 | 12.362146 | 13.290470 | 6.926239 | 11.205064 | 7.827393 | 11.953120 | 9.377511 | 9.469915 | 9.880812 | 14.582350 | 18.332051 |
2 | 13.710906 | 12.111122 | 12.879132 | 6.942411 | 11.551772 | 7.633858 | 11.206024 | 9.341437 | 9.313169 | 9.518051 | 13.728898 | 17.156142 |
3 | 13.158687 | 11.505842 | 12.648118 | 7.265907 | 11.554516 | 7.959409 | 11.310179 | 9.635896 | 9.700324 | 10.096953 | 13.810609 | 16.909317 |
4 | 12.555648 | 10.429759 | 12.204815 | 6.898037 | 10.677667 | 7.441389 | 10.221315 | 8.909056 | 8.930870 | 9.158019 | 12.664759 | 14.937611 |
5 | 11.724032 | 10.145619 | 11.550394 | 6.307487 | 10.224301 | 6.942061 | 8.797738 | 8.452903 | 8.040806 | 8.524857 | 12.767258 | 13.736039 |
6 | 10.451317 | 8.949704 | 10.361315 | 5.652278 | 9.529926 | 6.410093 | 8.009556 | 7.920796 | 7.639796 | 7.729185 | 12.246407 | 12.861818 |
7 | 9.992007 | 8.357778 | 9.349642 | 5.416935 | 9.302634 | 5.972348 | 7.843501 | 7.262760 | 7.544480 | 7.321416 | 11.676505 | 12.800789 |
8 | 10.213411 | 8.415143 | 9.993441 | 5.270681 | 8.901559 | 5.891057 | 7.772312 | 6.842025 | 7.240573 | 7.002783 | 11.110090 | 12.565943 |
9 | 11.458519 | 9.981002 | 10.756883 | 5.615176 | 9.766315 | 6.566222 | 8.609722 | 7.745677 | 7.610556 | 7.689278 | 12.686389 | 14.761963 |
10 | 12.660610 | 11.010681 | 11.453943 | 6.065215 | 10.550251 | 7.159910 | 9.387778 | 8.726308 | 8.347181 | 8.850376 | 14.155323 | 16.697151 |
11 | 13.778291 | 12.140912 | 12.663775 | 6.567949 | 10.952411 | 7.447849 | 11.137247 | 8.753590 | 8.874886 | 9.258917 | 14.044117 | 18.066268 |
12 | 14.486328 | 12.456597 | 13.100194 | 6.903722 | 11.354931 | 7.959569 | 11.711028 | 9.246833 | 9.439875 | 9.721625 | 14.257306 | 18.476042 |
Step 14. Downsample the record to a weekly frequency for each location.
data.groupby(data.index.isocalendar().week).mean()
RPT | VAL | ROS | KIL | SHA | BIR | DUB | CLA | MUL | CLO | BEL | MAL | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
week | ||||||||||||
1 | 13.920000 | 11.710880 | 12.853016 | 6.617302 | 10.473175 | 7.578492 | 11.623651 | 9.123600 | 9.272222 | 9.870635 | 14.241746 | 18.249841 |
2 | 15.444717 | 13.504528 | 14.104717 | 7.094906 | 12.230566 | 8.184717 | 12.113585 | 9.939245 | 9.692264 | 9.559434 | 14.948302 | 18.242830 |
3 | 13.676154 | 11.921538 | 13.295385 | 6.330769 | 11.052308 | 8.214615 | 11.654615 | 9.586154 | 9.337692 | 9.860769 | 14.151538 | 19.094615 |
4 | 16.208333 | 14.823333 | 16.127500 | 7.858333 | 13.040833 | 8.395000 | 13.055833 | 10.645833 | 10.765000 | 11.393333 | 16.794167 | 20.674167 |
5 | 14.640098 | 12.991569 | 13.281667 | 7.487647 | 11.969118 | 8.234902 | 12.148333 | 9.689216 | 9.834118 | 10.153431 | 14.735392 | 17.584608 |
6 | 13.203730 | 11.508492 | 12.142619 | 6.469127 | 11.025476 | 7.166746 | 11.115317 | 8.894206 | 9.323413 | 9.298175 | 13.903254 | 17.921587 |
7 | 14.517460 | 12.681349 | 13.219524 | 7.148160 | 12.141032 | 7.906190 | 11.390238 | 9.749524 | 9.417778 | 9.605476 | 13.776667 | 17.130159 |
8 | 13.422857 | 11.822937 | 13.367381 | 7.142400 | 11.480635 | 7.729683 | 11.329048 | 9.329762 | 9.247063 | 9.541984 | 13.132302 | 16.882540 |
9 | 12.761360 | 11.837460 | 12.627440 | 6.620000 | 10.937143 | 7.457778 | 10.622778 | 9.387778 | 8.864160 | 9.611508 | 13.724048 | 16.602080 |
10 | 13.526720 | 11.758095 | 13.151667 | 7.317063 | 11.477143 | 7.965397 | 10.751111 | 9.151825 | 9.367302 | 9.761429 | 13.055000 | 16.047381 |
11 | 13.597143 | 11.495079 | 13.032698 | 7.446270 | 11.689206 | 7.990238 | 11.444365 | 10.038968 | 9.783730 | 10.398730 | 13.823968 | 17.331280 |
12 | 13.006825 | 11.621032 | 12.579048 | 7.390476 | 11.850476 | 8.288095 | 12.008413 | 10.136746 | 10.176270 | 10.259048 | 14.389524 | 17.859365 |
13 | 12.772540 | 11.076349 | 12.104444 | 7.386640 | 11.664286 | 8.042063 | 11.306587 | 9.494365 | 9.977760 | 10.038571 | 14.241667 | 16.486508 |
14 | 13.903968 | 11.025238 | 14.149286 | 7.798968 | 11.482857 | 8.006905 | 11.525238 | 9.579921 | 9.894762 | 9.948175 | 13.386270 | 16.691349 |
15 | 12.599444 | 9.966667 | 11.654286 | 6.758175 | 10.642540 | 7.377778 | 10.677143 | 9.328413 | 9.248333 | 9.338413 | 12.842460 | 15.900476 |
16 | 12.753968 | 11.111587 | 11.966587 | 7.110000 | 10.983730 | 7.660794 | 9.981905 | 8.763571 | 8.802063 | 9.326905 | 12.472857 | 14.229524 |
17 | 10.966349 | 9.647698 | 11.272619 | 6.019286 | 9.627857 | 6.687063 | 8.870714 | 8.091825 | 7.836032 | 8.238333 | 11.971667 | 13.097460 |
18 | 12.897222 | 11.095079 | 11.256825 | 6.745794 | 11.035952 | 7.405238 | 9.318730 | 8.674206 | 8.340952 | 8.952857 | 12.928968 | 14.523810 |
19 | 13.061429 | 11.275159 | 12.630397 | 7.005238 | 10.944683 | 7.559603 | 9.624320 | 9.111349 | 8.604683 | 9.243254 | 13.721984 | 14.288016 |
20 | 11.338571 | 9.769200 | 11.566746 | 6.195238 | 9.967937 | 6.811429 | 8.732857 | 8.495317 | 7.984365 | 8.507540 | 12.740952 | 13.859286 |
21 | 11.282698 | 9.673889 | 11.223968 | 5.975680 | 10.051905 | 6.730476 | 8.435397 | 8.150556 | 7.871587 | 8.278413 | 12.536270 | 13.626825 |
22 | 9.673333 | 8.264683 | 10.382302 | 5.195397 | 8.696825 | 5.802063 | 7.275873 | 7.533016 | 7.120873 | 7.247222 | 11.238810 | 11.770317 |
23 | 10.092143 | 8.980556 | 10.030476 | 5.304048 | 8.882143 | 5.816825 | 7.420952 | 7.387857 | 7.031587 | 7.173810 | 11.605635 | 12.395476 |
24 | 10.131905 | 8.741984 | 10.518254 | 5.498492 | 8.997381 | 6.189762 | 7.320317 | 7.597143 | 7.172857 | 7.259524 | 11.835873 | 12.041270 |
25 | 11.680238 | 9.898016 | 10.730397 | 6.294444 | 11.030397 | 7.410952 | 9.410238 | 8.822698 | 8.728016 | 8.677063 | 13.494762 | 14.329841 |
26 | 10.036000 | 8.770635 | 10.113333 | 5.798492 | 9.680159 | 6.474603 | 8.226032 | 7.920556 | 7.906270 | 7.937778 | 12.462222 | 12.993840 |
27 | 9.991984 | 7.916984 | 8.741032 | 5.276825 | 8.998175 | 5.852302 | 7.817680 | 7.182143 | 7.662143 | 7.451349 | 11.582857 | 13.096984 |
28 | 9.962143 | 8.272619 | 9.651349 | 5.461270 | 9.344206 | 5.951111 | 7.937857 | 7.341746 | 7.671905 | 7.267063 | 11.450159 | 12.932460 |
29 | 10.281746 | 8.422063 | 9.755079 | 5.672778 | 9.766667 | 6.300238 | 8.277619 | 7.568175 | 7.725952 | 7.616349 | 12.021667 | 12.880476 |
30 | 9.760397 | 8.211984 | 9.181587 | 5.195476 | 8.920873 | 5.657222 | 7.566905 | 6.904603 | 7.078571 | 7.010317 | 11.410794 | 12.279683 |
31 | 9.721984 | 8.218571 | 9.585556 | 5.078651 | 8.940397 | 5.692857 | 7.470397 | 6.646746 | 7.039206 | 6.615556 | 11.020317 | 12.348492 |
32 | 10.202640 | 8.669683 | 9.357619 | 5.524206 | 9.143492 | 6.091984 | 7.518413 | 6.896190 | 7.409365 | 7.057840 | 11.154365 | 12.746587 |
33 | 10.213254 | 8.000476 | 10.086667 | 5.169127 | 8.638413 | 5.652619 | 7.635635 | 6.591746 | 7.033413 | 6.502460 | 10.647222 | 11.315680 |
34 | 10.675556 | 9.065317 | 10.466190 | 5.380635 | 9.343651 | 6.275317 | 8.164603 | 7.503889 | 7.753730 | 7.779206 | 11.881667 | 13.764762 |
35 | 10.378571 | 8.525476 | 10.496746 | 5.398571 | 8.739444 | 5.938968 | 8.088889 | 6.907857 | 7.063016 | 7.213175 | 11.606825 | 13.390873 |
36 | 10.764365 | 9.296190 | 9.931270 | 5.387381 | 9.245873 | 6.353810 | 8.314603 | 7.012857 | 7.449762 | 7.221905 | 11.597619 | 13.754921 |
37 | 11.371190 | 9.722857 | 10.963889 | 5.638810 | 9.603968 | 6.646587 | 8.698492 | 7.704841 | 7.532143 | 7.645952 | 12.658968 | 14.827540 |
38 | 9.929524 | 8.863095 | 10.245280 | 4.462080 | 8.346190 | 5.408175 | 7.285079 | 6.724640 | 6.387381 | 6.423095 | 11.394127 | 13.094921 |
39 | 13.960635 | 12.361920 | 11.787302 | 6.898095 | 11.971032 | 7.882540 | 10.012619 | 9.489206 | 8.933413 | 9.402540 | 14.980000 | 16.928095 |
40 | 12.199841 | 10.619127 | 11.392698 | 5.854048 | 10.308175 | 6.841508 | 9.301905 | 8.581111 | 8.561667 | 8.519524 | 13.326429 | 15.758095 |
41 | 12.260800 | 10.581508 | 11.316190 | 5.468889 | 9.998254 | 6.667460 | 8.667778 | 8.279444 | 7.782540 | 8.176825 | 13.550952 | 15.663571 |
42 | 12.777460 | 10.966587 | 11.381667 | 6.349048 | 10.716032 | 7.526032 | 9.941349 | 8.802222 | 8.460873 | 9.039286 | 14.088175 | 17.116111 |
43 | 13.358651 | 11.915238 | 11.888095 | 6.554286 | 11.363571 | 7.769524 | 10.170873 | 9.458889 | 8.925840 | 9.800873 | 16.055873 | 18.580952 |
44 | 14.077179 | 12.215077 | 12.850000 | 6.805128 | 11.049692 | 7.597077 | 10.420667 | 9.005949 | 8.835436 | 9.559487 | 14.284103 | 17.692462 |
45 | 14.400698 | 12.762605 | 13.244791 | 6.862791 | 11.556355 | 7.894000 | 11.490186 | 9.447116 | 9.364977 | 9.642093 | 14.449116 | 18.232791 |
46 | 14.096846 | 12.565000 | 13.101462 | 6.983154 | 11.603462 | 7.844615 | 11.637769 | 9.014615 | 9.155154 | 9.582923 | 14.284692 | 19.428923 |
47 | 11.731508 | 10.361667 | 11.107698 | 5.413968 | 9.200952 | 6.172540 | 10.071920 | 7.322222 | 7.690397 | 7.933095 | 12.399762 | 16.473254 |
48 | 13.817239 | 12.136074 | 12.050061 | 6.297791 | 11.072699 | 7.641472 | 11.273804 | 8.655706 | 8.907791 | 9.249939 | 14.161288 | 17.849571 |
49 | 14.776094 | 13.048205 | 12.752650 | 7.306880 | 11.743291 | 8.209444 | 12.114231 | 9.496624 | 9.844060 | 10.012222 | 14.860000 | 18.847436 |
50 | 14.520350 | 12.493846 | 12.796224 | 7.096643 | 11.650769 | 8.277483 | 11.867343 | 9.456434 | 9.483706 | 9.968462 | 14.752168 | 18.312517 |
51 | 13.639921 | 11.697619 | 12.501667 | 5.991270 | 10.541667 | 7.275159 | 10.301667 | 8.462619 | 8.438730 | 8.687937 | 13.298889 | 17.182063 |
52 | 14.469134 | 11.692283 | 14.210000 | 7.018189 | 10.856905 | 7.379213 | 12.011969 | 9.121811 | 9.665197 | 9.677953 | 13.549055 | 19.183228 |
53 | 12.694286 | 9.451905 | 13.526190 | 5.343810 | 8.040476 | 5.884286 | 10.366190 | 5.556190 | 6.954286 | 7.820952 | 11.028095 | 17.103810 |
Step 15. Calculate the min, max and mean windspeeds and standard deviations of the windspeeds across all locations for each week (assume that the first week starts on January 2 1961) for the first 52 weeks.
data.groupby(data.index.isocalendar().week).describe()
RPT | VAL | ... | BEL | MAL | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | mean | std | min | 25% | 50% | 75% | max | count | mean | ... | 75% | max | count | mean | std | min | 25% | 50% | 75% | max | |
week | |||||||||||||||||||||
1 | 126.0 | 13.920000 | 6.341312 | 2.62 | 9.2600 | 13.020 | 17.3850 | 33.34 | 125.0 | 11.710880 | ... | 18.8700 | 38.20 | 126.0 | 18.249841 | 7.047385 | 4.17 | 13.3225 | 17.435 | 23.2900 | 37.63 |
2 | 53.0 | 15.444717 | 5.462035 | 5.29 | 11.3400 | 15.090 | 19.7500 | 28.75 | 53.0 | 13.504528 | ... | 18.8400 | 31.08 | 53.0 | 18.242830 | 6.881317 | 3.63 | 12.5000 | 19.040 | 23.3300 | 31.75 |
3 | 13.0 | 13.676154 | 4.875431 | 7.54 | 9.7100 | 11.460 | 18.0800 | 22.37 | 13.0 | 11.921538 | ... | 15.5000 | 23.04 | 13.0 | 19.094615 | 6.579779 | 6.79 | 15.7500 | 19.550 | 20.8300 | 32.83 |
4 | 12.0 | 16.208333 | 6.112314 | 2.08 | 11.7600 | 17.870 | 19.5925 | 24.25 | 12.0 | 14.823333 | ... | 20.8150 | 29.88 | 12.0 | 20.674167 | 8.356038 | 12.29 | 14.1975 | 17.795 | 25.5275 | 40.12 |
5 | 102.0 | 14.640098 | 5.648340 | 2.71 | 10.8425 | 14.310 | 18.5375 | 33.84 | 102.0 | 12.991569 | ... | 19.1350 | 27.71 | 102.0 | 17.584608 | 6.482263 | 4.83 | 12.9350 | 17.625 | 22.1700 | 34.25 |
6 | 126.0 | 13.203730 | 5.620867 | 2.79 | 9.1800 | 12.105 | 17.3600 | 30.13 | 126.0 | 11.508492 | ... | 17.8200 | 28.12 | 126.0 | 17.921587 | 6.092634 | 5.29 | 12.9600 | 17.330 | 21.6925 | 33.04 |
7 | 126.0 | 14.517460 | 5.916627 | 2.92 | 10.2725 | 14.190 | 18.2925 | 29.17 | 126.0 | 12.681349 | ... | 18.2700 | 32.08 | 126.0 | 17.130159 | 6.819665 | 5.09 | 11.8225 | 16.315 | 21.7900 | 37.04 |
8 | 126.0 | 13.422857 | 5.923096 | 1.54 | 9.0625 | 12.310 | 17.4900 | 32.38 | 126.0 | 11.822937 | ... | 16.7275 | 35.08 | 126.0 | 16.882540 | 7.251216 | 3.04 | 11.3025 | 16.130 | 22.2200 | 38.20 |
9 | 125.0 | 12.761360 | 5.240324 | 0.67 | 9.0800 | 12.580 | 16.3800 | 28.91 | 126.0 | 11.837460 | ... | 18.7950 | 31.13 | 125.0 | 16.602080 | 6.191920 | 3.17 | 12.5000 | 15.750 | 20.5400 | 31.66 |
10 | 125.0 | 13.526720 | 6.165086 | 2.29 | 8.7100 | 12.620 | 17.0400 | 35.80 | 126.0 | 11.758095 | ... | 17.2275 | 32.63 | 126.0 | 16.047381 | 6.572057 | 2.46 | 11.3900 | 15.670 | 20.4700 | 37.59 |
11 | 126.0 | 13.597143 | 6.412912 | 1.46 | 8.8725 | 12.665 | 18.1450 | 33.04 | 126.0 | 11.495079 | ... | 19.0175 | 34.92 | 125.0 | 17.331280 | 7.428510 | 4.54 | 11.5400 | 16.880 | 21.4600 | 40.37 |
12 | 126.0 | 13.006825 | 5.509073 | 2.92 | 9.2400 | 12.645 | 16.8475 | 32.13 | 126.0 | 11.621032 | ... | 18.6875 | 31.71 | 126.0 | 17.859365 | 6.902719 | 3.21 | 13.2650 | 18.185 | 22.3075 | 37.99 |
13 | 126.0 | 12.772540 | 5.278774 | 2.79 | 8.6125 | 12.895 | 16.0500 | 27.12 | 126.0 | 11.076349 | ... | 17.5800 | 32.21 | 126.0 | 16.486508 | 6.644671 | 2.04 | 12.6525 | 15.955 | 20.3800 | 31.20 |
14 | 126.0 | 13.903968 | 5.698092 | 3.88 | 9.8225 | 13.790 | 17.4900 | 32.58 | 126.0 | 11.025238 | ... | 17.4100 | 25.50 | 126.0 | 16.691349 | 6.979889 | 3.71 | 11.8225 | 16.125 | 20.9775 | 34.08 |
15 | 126.0 | 12.599444 | 5.335705 | 4.42 | 8.4300 | 11.650 | 15.6900 | 29.79 | 126.0 | 9.966667 | ... | 15.9975 | 27.00 | 126.0 | 15.900476 | 6.795427 | 4.33 | 11.3225 | 14.335 | 20.7775 | 33.95 |
16 | 126.0 | 12.753968 | 5.248461 | 3.67 | 8.6325 | 12.145 | 16.2375 | 27.84 | 126.0 | 11.111587 | ... | 15.5675 | 23.96 | 126.0 | 14.229524 | 5.328738 | 4.17 | 10.4800 | 13.750 | 17.6975 | 28.67 |
17 | 126.0 | 10.966349 | 5.378706 | 3.46 | 6.3225 | 9.960 | 14.0900 | 26.83 | 126.0 | 9.647698 | ... | 15.7300 | 26.12 | 126.0 | 13.097460 | 6.018248 | 2.21 | 8.3800 | 12.580 | 16.8250 | 32.05 |
18 | 126.0 | 12.897222 | 4.367054 | 1.63 | 9.8825 | 12.830 | 16.0650 | 27.25 | 126.0 | 11.095079 | ... | 16.3800 | 28.33 | 126.0 | 14.523810 | 6.216011 | 2.58 | 10.2000 | 13.415 | 18.6475 | 28.75 |
19 | 126.0 | 13.061429 | 5.517038 | 3.54 | 8.5925 | 13.025 | 16.4900 | 30.91 | 126.0 | 11.275159 | ... | 17.2875 | 32.91 | 126.0 | 14.288016 | 5.699596 | 3.33 | 10.0625 | 14.500 | 18.3400 | 26.83 |
20 | 126.0 | 11.338571 | 5.404169 | 2.42 | 6.8400 | 10.125 | 15.0775 | 25.17 | 125.0 | 9.769200 | ... | 16.1475 | 26.42 | 126.0 | 13.859286 | 5.865042 | 3.58 | 9.5225 | 13.480 | 17.3850 | 32.17 |
21 | 126.0 | 11.282698 | 5.200316 | 2.62 | 7.5600 | 10.815 | 13.9725 | 28.79 | 126.0 | 9.673889 | ... | 15.6975 | 28.12 | 126.0 | 13.626825 | 5.258812 | 4.04 | 9.4550 | 13.480 | 16.6875 | 29.50 |
22 | 126.0 | 9.673333 | 4.053188 | 2.04 | 6.7300 | 9.250 | 11.9875 | 21.84 | 126.0 | 8.264683 | ... | 13.6575 | 26.38 | 126.0 | 11.770317 | 5.001233 | 1.75 | 7.8525 | 11.650 | 15.1000 | 28.04 |
23 | 126.0 | 10.092143 | 4.516349 | 2.17 | 6.7600 | 9.665 | 12.5700 | 23.21 | 126.0 | 8.980556 | ... | 14.5400 | 21.34 | 126.0 | 12.395476 | 5.383357 | 2.21 | 8.3825 | 11.895 | 16.0700 | 32.79 |
24 | 126.0 | 10.131905 | 4.410570 | 1.00 | 6.5400 | 9.960 | 12.8300 | 21.59 | 126.0 | 8.741984 | ... | 14.6475 | 25.25 | 126.0 | 12.041270 | 5.419266 | 2.79 | 7.8525 | 11.685 | 15.3400 | 27.16 |
25 | 126.0 | 11.680238 | 4.415008 | 2.92 | 7.9700 | 11.145 | 14.5300 | 22.71 | 126.0 | 9.898016 | ... | 16.2400 | 29.79 | 126.0 | 14.329841 | 5.873487 | 3.08 | 10.1400 | 14.020 | 17.4475 | 28.38 |
26 | 125.0 | 10.036000 | 3.868826 | 3.46 | 6.9200 | 9.670 | 12.7900 | 20.50 | 126.0 | 8.770635 | ... | 15.6050 | 24.71 | 125.0 | 12.993840 | 4.516285 | 4.54 | 9.3300 | 12.710 | 15.9200 | 25.17 |
27 | 126.0 | 9.991984 | 4.742847 | 2.00 | 6.7900 | 8.960 | 12.4100 | 25.84 | 126.0 | 7.916984 | ... | 14.5000 | 23.00 | 126.0 | 13.096984 | 5.292558 | 4.50 | 9.0800 | 12.560 | 16.2800 | 29.63 |
28 | 126.0 | 9.962143 | 4.661313 | 2.75 | 6.2500 | 9.105 | 13.3500 | 22.50 | 126.0 | 8.272619 | ... | 14.4175 | 23.83 | 126.0 | 12.932460 | 5.565273 | 2.13 | 8.7400 | 12.420 | 16.3200 | 28.46 |
29 | 126.0 | 10.281746 | 4.578130 | 1.71 | 6.8325 | 10.330 | 13.4575 | 22.34 | 126.0 | 8.422063 | ... | 15.2175 | 24.41 | 126.0 | 12.880476 | 5.472898 | 2.29 | 8.5000 | 12.810 | 17.3800 | 25.37 |
30 | 126.0 | 9.760397 | 4.056483 | 1.25 | 6.4800 | 9.335 | 12.5500 | 20.33 | 126.0 | 8.211984 | ... | 14.2700 | 22.37 | 126.0 | 12.279683 | 5.055287 | 2.88 | 8.2100 | 12.310 | 15.6900 | 25.37 |
31 | 126.0 | 9.721984 | 4.143365 | 2.79 | 6.5825 | 9.420 | 12.1075 | 22.42 | 126.0 | 8.218571 | ... | 13.7375 | 21.67 | 126.0 | 12.348492 | 5.053851 | 2.25 | 9.0925 | 12.625 | 16.3875 | 24.83 |
32 | 125.0 | 10.202640 | 3.982815 | 2.67 | 6.8700 | 10.250 | 13.1300 | 20.08 | 126.0 | 8.669683 | ... | 13.6925 | 24.08 | 126.0 | 12.746587 | 5.353812 | 3.04 | 8.9650 | 12.500 | 16.3125 | 29.95 |
33 | 126.0 | 10.213254 | 4.914926 | 3.17 | 6.6400 | 9.040 | 13.4075 | 26.38 | 126.0 | 8.000476 | ... | 13.5650 | 23.25 | 125.0 | 11.315680 | 5.587084 | 2.17 | 7.1700 | 10.750 | 14.6200 | 34.33 |
34 | 126.0 | 10.675556 | 4.874965 | 2.42 | 7.1700 | 10.460 | 14.2800 | 24.67 | 126.0 | 9.065317 | ... | 16.0700 | 24.83 | 126.0 | 13.764762 | 5.642352 | 3.37 | 9.1250 | 13.290 | 18.0000 | 30.46 |
35 | 126.0 | 10.378571 | 4.976603 | 0.96 | 6.0800 | 10.040 | 13.5900 | 23.38 | 126.0 | 8.525476 | ... | 14.7900 | 26.46 | 126.0 | 13.390873 | 5.962103 | 3.83 | 8.7500 | 12.395 | 17.3900 | 28.84 |
36 | 126.0 | 10.764365 | 5.086312 | 1.50 | 6.6500 | 10.400 | 14.3675 | 29.54 | 126.0 | 9.296190 | ... | 14.9150 | 24.17 | 126.0 | 13.754921 | 5.692819 | 3.37 | 9.4700 | 13.940 | 17.0300 | 30.34 |
37 | 126.0 | 11.371190 | 5.662910 | 1.79 | 7.2600 | 10.775 | 14.9800 | 31.42 | 126.0 | 9.722857 | ... | 16.2500 | 25.75 | 126.0 | 14.827540 | 6.350553 | 2.83 | 10.3800 | 14.830 | 18.0500 | 35.13 |
38 | 126.0 | 9.929524 | 4.585719 | 0.79 | 6.5325 | 9.165 | 12.7800 | 24.79 | 126.0 | 8.863095 | ... | 14.7400 | 23.04 | 126.0 | 13.094921 | 5.420672 | 0.67 | 9.0825 | 12.670 | 17.2975 | 29.63 |
39 | 126.0 | 13.960635 | 5.313510 | 3.37 | 10.0100 | 13.545 | 17.1300 | 27.00 | 125.0 | 12.361920 | ... | 19.4950 | 28.79 | 126.0 | 16.928095 | 6.943457 | 4.04 | 11.9125 | 15.895 | 20.8100 | 33.63 |
40 | 126.0 | 12.199841 | 4.458238 | 2.37 | 8.9200 | 12.380 | 15.0900 | 25.29 | 126.0 | 10.619127 | ... | 17.4275 | 26.71 | 126.0 | 15.758095 | 6.364950 | 2.04 | 11.2900 | 15.565 | 20.4100 | 32.96 |
41 | 125.0 | 12.260800 | 5.400736 | 3.04 | 8.2900 | 11.790 | 15.1600 | 25.92 | 126.0 | 10.581508 | ... | 17.4375 | 34.83 | 126.0 | 15.663571 | 6.537501 | 3.33 | 10.7200 | 15.120 | 19.9875 | 36.51 |
42 | 126.0 | 12.777460 | 5.718162 | 2.04 | 8.6600 | 12.145 | 16.2700 | 28.62 | 126.0 | 10.966587 | ... | 17.0825 | 32.63 | 126.0 | 17.116111 | 6.401907 | 5.04 | 12.1125 | 16.395 | 21.5900 | 33.45 |
43 | 126.0 | 13.358651 | 6.116732 | 1.50 | 9.0200 | 12.670 | 17.0100 | 29.08 | 126.0 | 11.915238 | ... | 20.7000 | 38.96 | 126.0 | 18.580952 | 6.799425 | 6.17 | 12.9900 | 17.965 | 23.4100 | 36.63 |
44 | 195.0 | 14.077179 | 5.833335 | 2.00 | 9.9600 | 13.620 | 17.5400 | 32.17 | 195.0 | 12.215077 | ... | 18.1450 | 39.04 | 195.0 | 17.692462 | 7.021542 | 4.54 | 12.3550 | 17.250 | 21.8400 | 37.59 |
45 | 215.0 | 14.400698 | 6.254240 | 1.63 | 9.7700 | 13.790 | 18.1200 | 33.12 | 215.0 | 12.762605 | ... | 18.7300 | 33.34 | 215.0 | 18.232791 | 7.140148 | 2.96 | 13.2900 | 17.960 | 23.1300 | 38.04 |
46 | 130.0 | 14.096846 | 6.405892 | 2.92 | 9.0800 | 13.000 | 18.7800 | 30.21 | 130.0 | 12.565000 | ... | 18.8800 | 31.96 | 130.0 | 19.428923 | 8.585392 | 2.00 | 13.1800 | 18.935 | 24.7150 | 41.25 |
47 | 126.0 | 11.731508 | 5.234852 | 2.67 | 8.0950 | 10.750 | 14.8300 | 26.50 | 126.0 | 10.361667 | ... | 16.4100 | 30.00 | 126.0 | 16.473254 | 6.677397 | 4.25 | 10.8625 | 15.710 | 20.8900 | 34.83 |
48 | 163.0 | 13.817239 | 6.125372 | 3.08 | 9.0800 | 13.170 | 17.8100 | 34.37 | 163.0 | 12.136074 | ... | 18.7900 | 42.38 | 163.0 | 17.849571 | 6.642826 | 4.79 | 12.7300 | 17.290 | 22.5850 | 42.54 |
49 | 233.0 | 14.776094 | 6.192947 | 0.67 | 10.3400 | 13.920 | 19.0800 | 35.38 | 234.0 | 13.048205 | ... | 18.8700 | 34.42 | 234.0 | 18.847436 | 7.020126 | 3.25 | 14.2300 | 19.165 | 23.0975 | 38.79 |
50 | 143.0 | 14.520350 | 6.803921 | 1.96 | 9.7300 | 14.420 | 18.2900 | 30.91 | 143.0 | 12.493846 | ... | 18.7900 | 29.25 | 143.0 | 18.312517 | 6.500093 | 6.50 | 13.6700 | 18.710 | 21.8950 | 37.12 |
51 | 126.0 | 13.639921 | 5.313674 | 1.79 | 9.5225 | 13.270 | 16.9950 | 28.71 | 126.0 | 11.697619 | ... | 17.2675 | 30.84 | 126.0 | 17.182063 | 6.303056 | 2.62 | 13.0100 | 16.685 | 20.7175 | 38.25 |
52 | 127.0 | 14.469134 | 5.701056 | 3.00 | 10.2450 | 13.620 | 18.1250 | 32.50 | 127.0 | 11.692283 | ... | 17.2300 | 31.25 | 127.0 | 19.183228 | 6.834899 | 4.58 | 14.6450 | 18.710 | 22.7700 | 41.46 |
53 | 21.0 | 12.694286 | 5.804934 | 3.71 | 8.6700 | 11.750 | 16.7500 | 23.83 | 21.0 | 9.451905 | ... | 13.3700 | 30.46 | 21.0 | 17.103810 | 5.909188 | 7.12 | 13.7000 | 16.580 | 23.1300 | 26.83 |
53 rows × 96 columns
Leave a comment