diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e671f45216968..ca4f5e18a214d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3477,7 +3477,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame: 0 1 3 1 2 4 - >>> df1_transposed = df1.T # or df1.transpose() + >>> df1_transposed = df1.T # or df1.transpose() >>> df1_transposed 0 1 col1 1 2 @@ -3507,7 +3507,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame: 0 Alice 9.5 False 0 1 Bob 8.0 True 0 - >>> df2_transposed = df2.T # or df2.transpose() + >>> df2_transposed = df2.T # or df2.transpose() >>> df2_transposed 0 1 name Alice Bob @@ -4744,7 +4744,7 @@ def assign(self, **kwargs) -> DataFrame: of the columns depends on another one defined within the same assign: >>> df.assign(temp_f=lambda x: x['temp_c'] * 9 / 5 + 32, - ... temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9) + ... temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9) temp_c temp_f temp_k Portland 17.0 62.6 290.15 Berkeley 25.0 77.0 298.15 @@ -5983,8 +5983,8 @@ class max_speed >>> columns = pd.MultiIndex.from_tuples([('speed', 'max'), ... ('species', 'type')]) >>> df = pd.DataFrame([(389.0, 'fly'), - ... ( 24.0, 'fly'), - ... ( 80.5, 'run'), + ... (24.0, 'fly'), + ... (80.5, 'run'), ... (np.nan, 'jump')], ... index=index, ... columns=columns) @@ -8262,14 +8262,14 @@ def groupby( 4 2 1 1 5 4 5 2 2 2 6 5 - >>> df.pivot(index="lev1", columns=["lev2", "lev3"],values="values") + >>> df.pivot(index="lev1", columns=["lev2", "lev3"], values="values") lev2 1 2 lev3 1 2 1 2 lev1 1 0.0 1.0 2.0 NaN 2 4.0 3.0 NaN 5.0 - >>> df.pivot(index=["lev1", "lev2"], columns=["lev3"],values="values") + >>> df.pivot(index=["lev1", "lev2"], columns=["lev3"], values="values") lev3 1 2 lev1 lev2 1 1 0.0 1.0 @@ -8317,7 +8317,8 @@ def pivot( Parameters ----------%s - values : column to aggregate, optional + values : list-like or scalar, optional + Column or columns to aggregate. index : column, Grouper, array, or list of the previous If an array is passed, it must be the same length as the data. The list can contain any of the other types (except list). @@ -8403,7 +8404,7 @@ def pivot( This first example aggregates values by taking the sum. >>> table = pd.pivot_table(df, values='D', index=['A', 'B'], - ... columns=['C'], aggfunc=np.sum) + ... columns=['C'], aggfunc=np.sum) >>> table C large small A B @@ -8415,7 +8416,7 @@ def pivot( We can also fill missing values using the `fill_value` parameter. >>> table = pd.pivot_table(df, values='D', index=['A', 'B'], - ... columns=['C'], aggfunc=np.sum, fill_value=0) + ... columns=['C'], aggfunc=np.sum, fill_value=0) >>> table C large small A B @@ -8427,8 +8428,7 @@ def pivot( The next example aggregates by taking the mean across multiple columns. >>> table = pd.pivot_table(df, values=['D', 'E'], index=['A', 'C'], - ... aggfunc={'D': np.mean, - ... 'E': np.mean}) + ... aggfunc={'D': np.mean, 'E': np.mean}) >>> table D E A C @@ -8441,8 +8441,8 @@ def pivot( value column. >>> table = pd.pivot_table(df, values=['D', 'E'], index=['A', 'C'], - ... aggfunc={'D': np.mean, - ... 'E': [min, max, np.mean]}) + ... aggfunc={'D': np.mean, + ... 'E': [min, max, np.mean]}) >>> table D E mean max mean min @@ -10926,7 +10926,8 @@ def to_timestamp( Returns ------- - DataFrame with DatetimeIndex + DataFrame + The DataFrame has a DatetimeIndex. """ new_obj = self.copy(deep=copy) @@ -10960,7 +10961,8 @@ def to_period( Returns ------- - DataFrame with PeriodIndex + DataFrame: + The DataFrame has a PeriodIndex. Examples -------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c893e9ce3d9a9..243dd741bad50 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4846,8 +4846,8 @@ def sort_values( 4 96hr 50 >>> from natsort import index_natsorted >>> df.sort_values( - ... by="time", - ... key=lambda x: np.argsort(index_natsorted(df["time"])) + ... by="time", + ... key=lambda x: np.argsort(index_natsorted(df["time"])) ... ) time value 0 0hr 10 @@ -7694,10 +7694,10 @@ def isna(self: NDFrameT) -> NDFrameT: Show which entries in a DataFrame are NA. >>> df = pd.DataFrame(dict(age=[5, 6, np.NaN], - ... born=[pd.NaT, pd.Timestamp('1939-05-27'), - ... pd.Timestamp('1940-04-25')], - ... name=['Alfred', 'Batman', ''], - ... toy=[None, 'Batmobile', 'Joker'])) + ... born=[pd.NaT, pd.Timestamp('1939-05-27'), + ... pd.Timestamp('1940-04-25')], + ... name=['Alfred', 'Batman', ''], + ... toy=[None, 'Batmobile', 'Joker'])) >>> df age born name toy 0 5.0 NaT Alfred None @@ -7761,10 +7761,10 @@ def notna(self: NDFrameT) -> NDFrameT: Show which entries in a DataFrame are not NA. >>> df = pd.DataFrame(dict(age=[5, 6, np.NaN], - ... born=[pd.NaT, pd.Timestamp('1939-05-27'), - ... pd.Timestamp('1940-04-25')], - ... name=['Alfred', 'Batman', ''], - ... toy=[None, 'Batmobile', 'Joker'])) + ... born=[pd.NaT, pd.Timestamp('1939-05-27'), + ... pd.Timestamp('1940-04-25')], + ... name=['Alfred', 'Batman', ''], + ... toy=[None, 'Batmobile', 'Joker'])) >>> df age born name toy 0 5.0 NaT Alfred None @@ -8153,6 +8153,7 @@ def at_time( Parameters ---------- time : datetime.time or str + The values to select. axis : {0 or 'index', 1 or 'columns'}, default 0 For `Series` this parameter is unused and defaults to 0. @@ -10109,7 +10110,8 @@ def tz_convert( tz : str or tzinfo object or None Target time zone. Passing ``None`` will convert to UTC and remove the timezone information. - axis : the axis to convert + axis : {{0 or 'index', 1 or 'columns'}}, default 0 + The axis to convert level : int, str, default None If axis is a MultiIndex, convert a specific level. Otherwise must be None. @@ -10130,8 +10132,10 @@ def tz_convert( -------- Change to another time zone: - >>> s = pd.Series([1], - ... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00'])) + >>> s = pd.Series( + ... [1], + ... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']), + ... ) >>> s.tz_convert('Asia/Shanghai') 2018-09-15 07:30:00+08:00 1 dtype: int64 @@ -10196,7 +10200,8 @@ def tz_localize( tz : str or tzinfo or None Time zone to localize. Passing ``None`` will remove the time zone information and preserve local time. - axis : the axis to localize + axis : {{0 or 'index', 1 or 'columns'}}, default 0 + The axis to localize level : int, str, default None If axis ia a MultiIndex, localize a specific level. Otherwise must be None. @@ -10245,8 +10250,10 @@ def tz_localize( -------- Localize local times: - >>> s = pd.Series([1], - ... index=pd.DatetimeIndex(['2018-09-15 01:30:00'])) + >>> s = pd.Series( + ... [1], + ... index=pd.DatetimeIndex(['2018-09-15 01:30:00']), + ... ) >>> s.tz_localize('CET') 2018-09-15 01:30:00+02:00 1 dtype: int64 @@ -10480,9 +10487,9 @@ def describe( Describing a timestamp ``Series``. >>> s = pd.Series([ - ... np.datetime64("2000-01-01"), - ... np.datetime64("2010-01-01"), - ... np.datetime64("2010-01-01") + ... np.datetime64("2000-01-01"), + ... np.datetime64("2010-01-01"), + ... np.datetime64("2010-01-01") ... ]) >>> s.describe() count 3 @@ -11740,9 +11747,9 @@ def _doc_params(cls): Examples -------- >>> df = pd.DataFrame({'person_id': [0, 1, 2, 3], -... 'age': [21, 25, 62, 43], -... 'height': [1.61, 1.87, 1.49, 2.01]} -... ).set_index('person_id') +... 'age': [21, 25, 62, 43], +... 'height': [1.61, 1.87, 1.49, 2.01]} +... ).set_index('person_id') >>> df age height person_id @@ -11960,7 +11967,7 @@ def _doc_params(cls): >>> df = pd.DataFrame([[2.0, 1.0], ... [3.0, np.nan], ... [1.0, 0.0]], -... columns=list('AB')) +... columns=list('AB')) >>> df A B 0 2.0 1.0 @@ -12025,7 +12032,7 @@ def _doc_params(cls): >>> df = pd.DataFrame([[2.0, 1.0], ... [3.0, np.nan], ... [1.0, 0.0]], -... columns=list('AB')) +... columns=list('AB')) >>> df A B 0 2.0 1.0 @@ -12090,7 +12097,7 @@ def _doc_params(cls): >>> df = pd.DataFrame([[2.0, 1.0], ... [3.0, np.nan], ... [1.0, 0.0]], -... columns=list('AB')) +... columns=list('AB')) >>> df A B 0 2.0 1.0 @@ -12155,7 +12162,7 @@ def _doc_params(cls): >>> df = pd.DataFrame([[2.0, 1.0], ... [3.0, np.nan], ... [1.0, 0.0]], -... columns=list('AB')) +... columns=list('AB')) >>> df A B 0 2.0 1.0 diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 147fa622fdedc..486fab62d93e7 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -798,8 +798,8 @@ Consider a dataset containing food consumption in Argentina. >>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48], - ... 'co2_emissions': [37.2, 19.66, 1712]}}, - ... index=['Pork', 'Wheat Products', 'Beef']) + ... 'co2_emissions': [37.2, 19.66, 1712]}}, + ... index=['Pork', 'Wheat Products', 'Beef']) >>> df consumption co2_emissions @@ -865,8 +865,8 @@ Consider a dataset containing food consumption in Argentina. >>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48], - ... 'co2_emissions': [37.2, 19.66, 1712]}}, - ... index=['Pork', 'Wheat Products', 'Beef']) + ... 'co2_emissions': [37.2, 19.66, 1712]}}, + ... index=['Pork', 'Wheat Products', 'Beef']) >>> df consumption co2_emissions diff --git a/pandas/core/window/doc.py b/pandas/core/window/doc.py index b1ff53e9d1a44..6e188531a0502 100644 --- a/pandas/core/window/doc.py +++ b/pandas/core/window/doc.py @@ -24,10 +24,10 @@ def create_section_header(header: str) -> str: template_see_also = dedent( """ - pandas.Series.{window_method} : Calling {window_method} with Series data. - pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames. - pandas.Series.{agg_method} : Aggregating {agg_method} for Series. - pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n + Series.{window_method} : Calling {window_method} with Series data. + DataFrame.{window_method} : Calling {window_method} with DataFrames. + Series.{agg_method} : Aggregating {agg_method} for Series. + DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n """ ).replace("\n", "", 1)