In [1]:
from pandas import Series, DataFrame
In [2]:
import pandas as pd
In [3]:
import numpy as np
In [4]:
weather = pd.read_table('data/daily_weather.tsv')
In [5]:
weather
Out[5]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
1
Spring
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
1
Spring
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
1
Spring
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
1
Spring
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
1
Spring
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
4
Winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
1
Spring
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
1
Spring
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
1
Spring
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
1
Spring
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
1
Spring
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
In [6]:
type(weather)
Out[6]:
pandas.core.frame.DataFrame
In [7]:
weather.groupby('season_desc')['temp'].mean()
Out[7]:
season_desc
Fall 0.711445
Spring 0.321700
Summer 0.554557
Winter 0.419368
Name: temp, dtype: float64
In [8]:
weather.loc[weather['season_code'] == 1, 'season_desc'] = 'winter'
In [9]:
weather
Out[9]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
1
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
1
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
4
Winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
4
Winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
4
Winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
4
Winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
1
winter
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
1
winter
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
In [10]:
weather.loc[weather['season_code'] == 2, 'season_desc'] = 'spring'
In [11]:
weather.loc[weather['season_code'] == 3, 'season_desc'] = 'summer'
In [12]:
weather.loc[weather['season_code'] == 4, 'season_desc'] = 'fall'
In [13]:
weather
Out[13]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
1
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
1
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
1
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
4
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
4
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
4
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
4
fall
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
4
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
4
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
4
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
1
winter
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
1
winter
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
1
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
1
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
1
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
In [14]:
weather.loc[weather['season_desc'] == 'winter', 'season_code'] = 4
In [15]:
weather.loc[weather['season_desc'] == 'spring', 'season_code'] = 1
In [16]:
weather.loc[weather['season_desc'] == 'summer', 'season_code'] = 2
In [17]:
weather.loc[weather['season_desc'] == 'fall', 'season_code'] = 3
In [18]:
weather.groupby('season_desc')['temp'].mean()
Out[18]:
season_desc
fall 0.419368
spring 0.554557
summer 0.711445
winter 0.321700
Name: temp, dtype: float64
In [19]:
weather
Out[19]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
3
fall
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
4
winter
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
4
winter
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
df[df['A'] > 2]['B'] = new_val # new_val not set in df
The warning offers a suggestion to rewrite as follows:
df.loc[df['A'] > 2, 'B'] = new_val
However, this doesn't fit your usage, which is equivalent to:
df = df[df['A'] > 2]
df['B'] = new_val
Warning we got on trying to rewrite certain dataframe rows, which led us to use .loc.
In [20]:
weather['date'] = pd.to_datetime(weather['date'])
In [21]:
weather.date
Out[21]:
0 2012-01-01
1 2012-01-02
2 2012-01-03
3 2012-01-04
4 2012-01-05
5 2012-01-06
6 2012-01-07
7 2012-01-08
8 2012-01-09
9 2012-01-10
10 2012-01-11
11 2012-01-12
12 2012-01-13
13 2012-01-14
14 2012-01-15
15 2012-01-16
16 2012-01-17
17 2012-01-18
18 2012-01-19
19 2012-01-20
20 2012-01-21
21 2012-01-22
22 2012-01-23
23 2012-01-24
24 2012-01-25
25 2012-01-26
26 2012-01-27
27 2012-01-28
28 2012-01-29
29 2012-01-30
...
336 2012-12-02
337 2012-12-03
338 2012-12-04
339 2012-12-05
340 2012-12-06
341 2012-12-07
342 2012-12-08
343 2012-12-09
344 2012-12-10
345 2012-12-11
346 2012-12-12
347 2012-12-13
348 2012-12-14
349 2012-12-15
350 2012-12-16
351 2012-12-17
352 2012-12-18
353 2012-12-19
354 2012-12-20
355 2012-12-21
356 2012-12-22
357 2012-12-23
358 2012-12-24
359 2012-12-25
360 2012-12-26
361 2012-12-27
362 2012-12-28
363 2012-12-29
364 2012-12-30
365 2012-12-31
Name: date, dtype: datetime64[ns]
In [22]:
weather['date'].dt.month
Out[22]:
0 1
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
..
336 12
337 12
338 12
339 12
340 12
341 12
342 12
343 12
344 12
345 12
346 12
347 12
348 12
349 12
350 12
351 12
352 12
353 12
354 12
355 12
356 12
357 12
358 12
359 12
360 12
361 12
362 12
363 12
364 12
365 12
dtype: int64
In [23]:
weather.groupby(weather['date'].dt.month)['total_riders'].sum()
Out[23]:
1 96744
2 103137
3 164875
4 174224
5 195865
6 202830
7 203607
8 214503
9 218573
10 198841
11 152664
12 123713
Name: total_riders, dtype: int64
In [24]:
weather
Out[24]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
3
fall
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
4
winter
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
4
winter
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
In [25]:
weather.groupby(weather['date'].dt.month)['total_riders'].sum()
Out[25]:
1 96744
2 103137
3 164875
4 174224
5 195865
6 202830
7 203607
8 214503
9 218573
10 198841
11 152664
12 123713
Name: total_riders, dtype: int64
In [26]:
weather.groupby(weather['season_desc'])['total_riders'].sum()
Out[26]:
season_desc
fall 515476
spring 571273
summer 641479
winter 321348
Name: total_riders, dtype: int64
In [27]:
weather['total_riders'].groupby(pd.cut(weather['temp'], np.arange(0, 1.0+0.2, 0.2))).sum()
Out[27]:
temp
(0, 0.2] 19805
(0.2, 0.4] 468929
(0.4, 0.6] 705947
(0.6, 0.8] 809250
(0.8, 1] 45645
Name: total_riders, dtype: int64
notes from next-day review:
In [35]:
weather[['season_desc', 'temp', 'total_riders']].groupby('season_desc').corr()
Out[35]:
temp
total_riders
season_desc
fall
temp
1.000000
0.626532
total_riders
0.626532
1.000000
spring
temp
1.000000
0.415687
total_riders
0.415687
1.000000
summer
temp
1.000000
-0.325743
total_riders
-0.325743
1.000000
winter
temp
1.000000
0.811410
total_riders
0.811410
1.000000
In [28]:
weather
Out[28]:
date
weekday
season_code
season_desc
is_holiday
is_work_day
weather_code
weather_desc
temp
subjective_temp
humidity
windspeed
no_casual_riders
no_reg_riders
total_riders
0
2012-01-01
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.370000
0.375621
0.692500
0.192167
686
1608
2294
1
2012-01-02
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.273043
0.252304
0.381304
0.329665
244
1707
1951
2
2012-01-03
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.150000
0.126275
0.441250
0.365671
89
2147
2236
3
2012-01-04
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.107500
0.119337
0.414583
0.184700
95
2273
2368
4
2012-01-05
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.278412
0.524167
0.129987
140
3132
3272
5
2012-01-06
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.334167
0.340267
0.542083
0.167908
307
3791
4098
6
2012-01-07
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.393333
0.390779
0.531667
0.174758
1070
3451
4521
7
2012-01-08
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.337500
0.340258
0.465000
0.191542
599
2826
3425
8
2012-01-09
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.224167
0.247479
0.701667
0.098900
106
2270
2376
9
2012-01-10
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.308696
0.318826
0.646522
0.187552
173
3425
3598
10
2012-01-11
3
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.274167
0.282821
0.847500
0.131221
92
2085
2177
11
2012-01-12
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.382500
0.381938
0.802917
0.180967
269
3828
4097
12
2012-01-13
5
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.274167
0.249362
0.507500
0.378108
174
3040
3214
13
2012-01-14
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.180000
0.183087
0.457500
0.187183
333
2160
2493
14
2012-01-15
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.166667
0.161625
0.419167
0.251258
284
2027
2311
15
2012-01-16
1
4
winter
1
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190663
0.522500
0.231358
217
2081
2298
16
2012-01-17
2
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.373043
0.364278
0.716087
0.349130
127
2808
2935
17
2012-01-18
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.303333
0.275254
0.443333
0.415429
109
3267
3376
18
2012-01-19
4
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.190000
0.190038
0.497500
0.220158
130
3162
3292
19
2012-01-20
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.217500
0.220958
0.450000
0.202750
115
3048
3163
20
2012-01-21
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.173333
0.174875
0.831250
0.222642
67
1234
1301
21
2012-01-22
0
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.162500
0.162250
0.796250
0.199638
196
1781
1977
22
2012-01-23
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.218333
0.243058
0.911250
0.110708
145
2287
2432
23
2012-01-24
2
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.342500
0.349108
0.835833
0.123767
439
3900
4339
24
2012-01-25
3
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.294167
0.294821
0.643750
0.161071
467
3803
4270
25
2012-01-26
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.341667
0.356050
0.769583
0.073396
244
3831
4075
26
2012-01-27
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.425000
0.415383
0.741250
0.342667
269
3187
3456
27
2012-01-28
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.315833
0.326379
0.543333
0.210829
775
3248
4023
28
2012-01-29
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.282500
0.272721
0.311250
0.240050
558
2685
3243
29
2012-01-30
1
4
winter
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.269167
0.262625
0.400833
0.215792
126
3498
3624
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
336
2012-12-02
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.347500
0.359208
0.823333
0.124379
892
3757
4649
337
2012-12-03
1
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.452500
0.455796
0.767500
0.082721
555
5679
6234
338
2012-12-04
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.475833
0.469054
0.733750
0.174129
551
6055
6606
339
2012-12-05
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.438333
0.428012
0.485000
0.324021
331
5398
5729
340
2012-12-06
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.258204
0.508750
0.174754
340
5035
5375
341
2012-12-07
5
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.320833
0.321958
0.764167
0.130600
349
4659
5008
342
2012-12-08
6
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.381667
0.389508
0.911250
0.101379
1153
4429
5582
343
2012-12-09
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.384167
0.390146
0.905417
0.157975
441
2787
3228
344
2012-12-10
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.435833
0.435575
0.925000
0.190308
329
4841
5170
345
2012-12-11
2
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.353333
0.338363
0.596667
0.296037
282
5219
5501
346
2012-12-12
3
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.297500
0.297338
0.538333
0.162937
310
5009
5319
347
2012-12-13
4
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.295833
0.294188
0.485833
0.174129
425
5107
5532
348
2012-12-14
5
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.281667
0.294192
0.642917
0.131229
429
5182
5611
349
2012-12-15
6
3
fall
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.324167
0.338383
0.650417
0.106350
767
4280
5047
350
2012-12-16
0
3
fall
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.362500
0.369938
0.838750
0.100742
538
3248
3786
351
2012-12-17
1
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.393333
0.401500
0.907083
0.098258
212
4373
4585
352
2012-12-18
2
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.410833
0.409708
0.666250
0.221404
433
5124
5557
353
2012-12-19
3
3
fall
0
1
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.332500
0.342162
0.625417
0.184092
333
4934
5267
354
2012-12-20
4
3
fall
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.330000
0.335217
0.667917
0.132463
314
3814
4128
355
2012-12-21
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.326667
0.301767
0.556667
0.374383
221
3402
3623
356
2012-12-22
6
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.265833
0.236113
0.441250
0.407346
205
1544
1749
357
2012-12-23
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.245833
0.259471
0.515417
0.133083
408
1379
1787
358
2012-12-24
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.231304
0.258900
0.791304
0.077230
174
746
920
359
2012-12-25
2
4
winter
1
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.291304
0.294465
0.734783
0.168726
440
573
1013
360
2012-12-26
3
4
winter
0
1
3
Light Snow, Light Rain + Thunderstorm + Scatte...
0.243333
0.220333
0.823333
0.316546
9
432
441
361
2012-12-27
4
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.254167
0.226642
0.652917
0.350133
247
1867
2114
362
2012-12-28
5
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.255046
0.590000
0.155471
644
2451
3095
363
2012-12-29
6
4
winter
0
0
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.253333
0.242400
0.752917
0.124383
159
1182
1341
364
2012-12-30
0
4
winter
0
0
1
Clear, Few clouds, Partly cloudy, Partly cloudy
0.255833
0.231700
0.483333
0.350754
364
1432
1796
365
2012-12-31
1
4
winter
0
1
2
Mist + Cloudy, Mist + Broken clouds, Mist + Fe...
0.215833
0.223487
0.577500
0.154846
439
2290
2729
366 rows × 15 columns
In [29]:
weather.groupby(weather['season_desc'])['no_casual_riders', 'no_reg_riders'].sum()
Out[29]:
no_casual_riders
no_reg_riders
season_desc
fall
76969
438507
spring
125958
445315
summer
130641
510838
winter
39197
282151
In [30]:
weather.groupby(pd.cut(weather['windspeed'], np.arange(0, 1.0+0.2, 0.2)))['no_casual_riders', 'no_reg_riders'].sum()
Out[30]:
no_casual_riders
no_reg_riders
windspeed
(0, 0.2]
247690
1111838
(0.2, 0.4]
123438
547273
(0.4, 0.6]
1637
17700
(0.6, 0.8]
NaN
NaN
(0.8, 1]
NaN
NaN
In [31]:
weather.groupby(pd.cut(weather['temp'], np.arange(0, 1.0+0.2, 0.2)))['no_casual_riders', 'no_reg_riders'].sum()
Out[31]:
no_casual_riders
no_reg_riders
temp
(0, 0.2]
1484
18321
(0.2, 0.4]
55084
413845
(0.4, 0.6]
136114
569833
(0.6, 0.8]
170712
638538
(0.8, 1]
9371
36274
In [32]:
weather.groupby(weather['weather_desc'])['no_casual_riders', 'no_reg_riders'].sum()
Out[32]:
no_casual_riders
no_reg_riders
weather_desc
Clear, Few clouds, Partly cloudy, Partly cloudy
269074
1153811
Light Snow, Light Rain + Thunderstorm + Scattered clouds, Light Rain + Scattered clouds
1902
10855
Mist + Cloudy, Mist + Broken clouds, Mist + Few clouds, Mist
101789
512145
In [ ]:
Content source: tlake/bikeshare
Similar notebooks: