@@ -790,7 +790,7 @@ def pop(self, item):
790
790
>>> df = pd.DataFrame([('falcon', 'bird', 389.0),
791
791
... ('parrot', 'bird', 24.0),
792
792
... ('lion', 'mammal', 80.5),
793
- ... ('monkey','mammal', np.nan)],
793
+ ... ('monkey', 'mammal', np.nan)],
794
794
... columns=('name', 'class', 'max_speed'))
795
795
>>> df
796
796
name class max_speed
@@ -2785,12 +2785,12 @@ def to_xarray(self):
2785
2785
2786
2786
Examples
2787
2787
--------
2788
- >>> df = pd.DataFrame([('falcon', 'bird', 389.0, 2),
2788
+ >>> df = pd.DataFrame([('falcon', 'bird', 389.0, 2),
2789
2789
... ('parrot', 'bird', 24.0, 2),
2790
- ... ('lion', 'mammal', 80.5, 4),
2790
+ ... ('lion', 'mammal', 80.5, 4),
2791
2791
... ('monkey', 'mammal', np.nan, 4)],
2792
- ... columns=['name', 'class', 'max_speed',
2793
- ... 'num_legs'])
2792
+ ... columns=['name', 'class', 'max_speed',
2793
+ ... 'num_legs'])
2794
2794
>>> df
2795
2795
name class max_speed num_legs
2796
2796
0 falcon bird 389.0 2
@@ -2818,10 +2818,11 @@ class (index) object 'bird' 'bird' 'mammal' 'mammal'
2818
2818
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-01',
2819
2819
... '2018-01-02', '2018-01-02'])
2820
2820
>>> df_multiindex = pd.DataFrame({'date': dates,
2821
- ... 'animal': ['falcon', 'parrot', 'falcon',
2822
- ... 'parrot'],
2823
- ... 'speed': [350, 18, 361, 15]}).set_index(['date',
2824
- ... 'animal'])
2821
+ ... 'animal': ['falcon', 'parrot',
2822
+ ... 'falcon', 'parrot'],
2823
+ ... 'speed': [350, 18, 361, 15]})
2824
+ >>> df_multiindex = df_multiindex.set_index(['date', 'animal'])
2825
+
2825
2826
>>> df_multiindex
2826
2827
speed
2827
2828
date animal
@@ -3307,12 +3308,12 @@ def take(self, indices, axis=0, is_copy: bool_t = True, **kwargs):
3307
3308
3308
3309
Examples
3309
3310
--------
3310
- >>> df = pd.DataFrame([('falcon', 'bird', 389.0),
3311
- ... ('parrot', 'bird', 24.0),
3312
- ... ('lion', 'mammal', 80.5),
3311
+ >>> df = pd.DataFrame([('falcon', 'bird', 389.0),
3312
+ ... ('parrot', 'bird', 24.0),
3313
+ ... ('lion', 'mammal', 80.5),
3313
3314
... ('monkey', 'mammal', np.nan)],
3314
- ... columns=['name', 'class', 'max_speed'],
3315
- ... index=[0, 2, 3, 1])
3315
+ ... columns=['name', 'class', 'max_speed'],
3316
+ ... index=[0, 2, 3, 1])
3316
3317
>>> df
3317
3318
name class max_speed
3318
3319
0 falcon bird 389.0
@@ -3814,9 +3815,10 @@ def reindex_like(
3814
3815
... [31, 87.8, 'high'],
3815
3816
... [22, 71.6, 'medium'],
3816
3817
... [35, 95, 'medium']],
3817
- ... columns=['temp_celsius', 'temp_fahrenheit', 'windspeed'],
3818
- ... index=pd.date_range(start='2014-02-12',
3819
- ... end='2014-02-15', freq='D'))
3818
+ ... columns=['temp_celsius', 'temp_fahrenheit',
3819
+ ... 'windspeed'],
3820
+ ... index=pd.date_range(start='2014-02-12',
3821
+ ... end='2014-02-15', freq='D'))
3820
3822
3821
3823
>>> df1
3822
3824
temp_celsius temp_fahrenheit windspeed
@@ -3828,9 +3830,9 @@ def reindex_like(
3828
3830
>>> df2 = pd.DataFrame([[28, 'low'],
3829
3831
... [30, 'low'],
3830
3832
... [35.1, 'medium']],
3831
- ... columns=['temp_celsius', 'windspeed'],
3832
- ... index=pd.DatetimeIndex(['2014-02-12', '2014-02-13',
3833
- ... '2014-02-15']))
3833
+ ... columns=['temp_celsius', 'windspeed'],
3834
+ ... index=pd.DatetimeIndex(['2014-02-12', '2014-02-13',
3835
+ ... '2014-02-15']))
3834
3836
3835
3837
>>> df2
3836
3838
temp_celsius windspeed
@@ -4000,7 +4002,7 @@ def add_prefix(self, prefix: str):
4000
4002
item_3 4
4001
4003
dtype: int64
4002
4004
4003
- >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
4005
+ >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
4004
4006
>>> df
4005
4007
A B
4006
4008
0 1 3
@@ -4059,7 +4061,7 @@ def add_suffix(self, suffix: str):
4059
4061
3_item 4
4060
4062
dtype: int64
4061
4063
4062
- >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
4064
+ >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
4063
4065
>>> df
4064
4066
A B
4065
4067
0 1 3
@@ -4308,10 +4310,9 @@ def reindex(self, *args, **kwargs):
4308
4310
Create a dataframe with some fictional data.
4309
4311
4310
4312
>>> index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror']
4311
- >>> df = pd.DataFrame({
4312
- ... 'http_status': [200,200,404,404,301],
4313
- ... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
4314
- ... index=index)
4313
+ >>> df = pd.DataFrame({'http_status': [200, 200, 404, 404, 301],
4314
+ ... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
4315
+ ... index=index)
4315
4316
>>> df
4316
4317
http_status response_time
4317
4318
Firefox 200 0.04
@@ -4324,8 +4325,8 @@ def reindex(self, *args, **kwargs):
4324
4325
values in the new index that do not have corresponding
4325
4326
records in the dataframe are assigned ``NaN``.
4326
4327
4327
- >>> new_index= ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10',
4328
- ... 'Chrome']
4328
+ >>> new_index = ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10',
4329
+ ... 'Chrome']
4329
4330
>>> df.reindex(new_index)
4330
4331
http_status response_time
4331
4332
Safari 404.0 0.07
@@ -4677,7 +4678,7 @@ def head(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4677
4678
4678
4679
Examples
4679
4680
--------
4680
- >>> df = pd.DataFrame({'animal':['alligator', 'bee', 'falcon', 'lion',
4681
+ >>> df = pd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion',
4681
4682
... 'monkey', 'parrot', 'shark', 'whale', 'zebra']})
4682
4683
>>> df
4683
4684
animal
@@ -4736,7 +4737,7 @@ def tail(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4736
4737
4737
4738
Examples
4738
4739
--------
4739
- >>> df = pd.DataFrame({'animal':['alligator', 'bee', 'falcon', 'lion',
4740
+ >>> df = pd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion',
4740
4741
... 'monkey', 'parrot', 'shark', 'whale', 'zebra']})
4741
4742
>>> df
4742
4743
animal
@@ -8046,7 +8047,7 @@ def last(self, offset):
8046
8047
Examples
8047
8048
--------
8048
8049
>>> i = pd.date_range('2018-04-09', periods=4, freq='2D')
8049
- >>> ts = pd.DataFrame({'A': [1,2,3, 4]}, index=i)
8050
+ >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i)
8050
8051
>>> ts
8051
8052
A
8052
8053
2018-04-09 1
@@ -9025,7 +9026,7 @@ def truncate(
9025
9026
>>> df = pd.DataFrame({'A': ['a', 'b', 'c', 'd', 'e'],
9026
9027
... 'B': ['f', 'g', 'h', 'i', 'j'],
9027
9028
... 'C': ['k', 'l', 'm', 'n', 'o']},
9028
- ... index=[1, 2, 3, 4, 5])
9029
+ ... index=[1, 2, 3, 4, 5])
9029
9030
>>> df
9030
9031
A B C
9031
9032
1 a f k
@@ -9266,22 +9267,22 @@ def tz_localize(
9266
9267
Localize local times:
9267
9268
9268
9269
>>> s = pd.Series([1],
9269
- ... index=pd.DatetimeIndex(['2018-09-15 01:30:00']))
9270
+ ... index=pd.DatetimeIndex(['2018-09-15 01:30:00']))
9270
9271
>>> s.tz_localize('CET')
9271
9272
2018-09-15 01:30:00+02:00 1
9272
9273
dtype: int64
9273
9274
9274
9275
Be careful with DST changes. When there is sequential data, pandas
9275
9276
can infer the DST time:
9276
9277
9277
- >>> s = pd.Series(range(7), index=pd.DatetimeIndex([
9278
- ... '2018-10-28 01:30:00',
9279
- ... '2018-10-28 02:00:00',
9280
- ... '2018-10-28 02:30:00',
9281
- ... '2018-10-28 02:00:00',
9282
- ... '2018-10-28 02:30:00',
9283
- ... '2018-10-28 03:00:00',
9284
- ... '2018-10-28 03:30:00']))
9278
+ >>> s = pd.Series(range(7),
9279
+ ... index=pd.DatetimeIndex([ '2018-10-28 01:30:00',
9280
+ ... '2018-10-28 02:00:00',
9281
+ ... '2018-10-28 02:30:00',
9282
+ ... '2018-10-28 02:00:00',
9283
+ ... '2018-10-28 02:30:00',
9284
+ ... '2018-10-28 03:00:00',
9285
+ ... '2018-10-28 03:30:00']))
9285
9286
>>> s.tz_localize('CET', ambiguous='infer')
9286
9287
2018-10-28 01:30:00+02:00 0
9287
9288
2018-10-28 02:00:00+02:00 1
@@ -9295,10 +9296,10 @@ def tz_localize(
9295
9296
In some cases, inferring the DST is impossible. In such cases, you can
9296
9297
pass an ndarray to the ambiguous parameter to set the DST explicitly
9297
9298
9298
- >>> s = pd.Series(range(3), index=pd.DatetimeIndex([
9299
- ... '2018-10-28 01:20:00',
9300
- ... '2018-10-28 02:36:00',
9301
- ... '2018-10-28 03:46:00']))
9299
+ >>> s = pd.Series(range(3),
9300
+ ... index=pd.DatetimeIndex([ '2018-10-28 01:20:00',
9301
+ ... '2018-10-28 02:36:00',
9302
+ ... '2018-10-28 03:46:00']))
9302
9303
>>> s.tz_localize('CET', ambiguous=np.array([True, True, False]))
9303
9304
2018-10-28 01:20:00+02:00 0
9304
9305
2018-10-28 02:36:00+02:00 1
@@ -9308,9 +9309,9 @@ def tz_localize(
9308
9309
If the DST transition causes nonexistent times, you can shift these
9309
9310
dates forward or backwards with a timedelta object or `'shift_forward'`
9310
9311
or `'shift_backwards'`.
9311
- >>> s = pd.Series(range(2), index=pd.DatetimeIndex([
9312
- ... '2015-03-29 02:30:00',
9313
- ... '2015-03-29 03:30:00']))
9312
+ >>> s = pd.Series(range(2),
9313
+ ... index=pd.DatetimeIndex([ '2015-03-29 02:30:00',
9314
+ ... '2015-03-29 03:30:00']))
9314
9315
>>> s.tz_localize('Europe/Warsaw', nonexistent='shift_forward')
9315
9316
2015-03-29 03:00:00+02:00 0
9316
9317
2015-03-29 03:30:00+02:00 1
0 commit comments