Skip to content

Commit 141e93a

Browse files
committed
Merge pull request #5560 from jorisvandenbossche/docstring-numpydoc-cleanup
DOC: styling clean-up of docstrings (part 1, frame.py)
2 parents 39ad4cb + a34b278 commit 141e93a

File tree

1 file changed

+79
-61
lines changed

1 file changed

+79
-61
lines changed

pandas/core/frame.py

+79-61
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ class DataFrame(NDFrame):
170170
171171
See also
172172
--------
173-
DataFrame.from_records: constructor from tuples, also record arrays
174-
DataFrame.from_dict: from dicts of Series, arrays, or dicts
175-
DataFrame.from_csv: from CSV files
176-
DataFrame.from_items: from sequence of (key, value) pairs
177-
read_csv / read_table / read_clipboard
173+
DataFrame.from_records : constructor from tuples, also record arrays
174+
DataFrame.from_dict : from dicts of Series, arrays, or dicts
175+
DataFrame.from_csv : from CSV files
176+
DataFrame.from_items : from sequence of (key, value) pairs
177+
pandas.read_csv, pandas.read_table, pandas.read_clipboard
178178
"""
179179
_auto_consolidate = True
180180

@@ -728,7 +728,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
728728
index : string, list of fields, array-like
729729
Field of array to use as the index, alternately a specific set of
730730
input labels to use
731-
exclude: sequence, default None
731+
exclude : sequence, default None
732732
Columns or fields to exclude
733733
columns : sequence, default None
734734
Column names to use. If the passed data do not have named
@@ -1167,8 +1167,10 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
11671167
Column label for index column(s) if desired. If None is given, and
11681168
`header` and `index` are True, then the index names are used. A
11691169
sequence should be given if the DataFrame uses MultiIndex.
1170-
startow : upper left cell row to dump data frame
1171-
startcol : upper left cell column to dump data frame
1170+
startow :
1171+
upper left cell row to dump data frame
1172+
startcol :
1173+
upper left cell column to dump data frame
11721174
engine : string, default None
11731175
write engine to use - you can also set this via the options
11741176
``io.excel.xlsx.writer``, ``io.excel.xls.writer``, and
@@ -1180,7 +1182,7 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
11801182
-----
11811183
If passing an existing ExcelWriter object, then the sheet will be added
11821184
to the existing workbook. This can be used to save different
1183-
DataFrames to one workbook
1185+
DataFrames to one workbook:
11841186
11851187
>>> writer = ExcelWriter('output.xlsx')
11861188
>>> df1.to_excel(writer,'Sheet1')
@@ -1249,13 +1251,14 @@ def to_sql(self, name, con, flavor='sqlite', if_exists='fail', **kwargs):
12491251
12501252
Parameters
12511253
----------
1252-
name: name of SQL table
1253-
conn: an open SQL database connection object
1254+
name : str
1255+
Name of SQL table
1256+
conn : an open SQL database connection object
12541257
flavor: {'sqlite', 'mysql', 'oracle'}, default 'sqlite'
12551258
if_exists: {'fail', 'replace', 'append'}, default 'fail'
1256-
fail: If table exists, do nothing.
1257-
replace: If table exists, drop it, recreate it, and insert data.
1258-
append: If table exists, insert data. Create if does not exist.
1259+
- fail: If table exists, do nothing.
1260+
- replace: If table exists, drop it, recreate it, and insert data.
1261+
- append: If table exists, insert data. Create if does not exist.
12591262
"""
12601263
from pandas.io.sql import write_frame
12611264
write_frame(
@@ -1316,6 +1319,7 @@ def to_html(self, buf=None, columns=None, col_space=None, colSpace=None,
13161319
CSS class(es) to apply to the resulting html table
13171320
escape : boolean, default True
13181321
Convert the characters <, >, and & to HTML-safe sequences.
1322+
13191323
"""
13201324

13211325
if force_unicode is not None: # pragma: no cover
@@ -1355,6 +1359,7 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None,
13551359
13561360
bold_rows : boolean, default True
13571361
Make the row labels bold in the output
1362+
13581363
"""
13591364

13601365
if force_unicode is not None: # pragma: no cover
@@ -1923,8 +1928,9 @@ def _set_item(self, key, value):
19231928
def insert(self, loc, column, value, allow_duplicates=False):
19241929
"""
19251930
Insert column into DataFrame at specified location.
1926-
if allow_duplicates is False, Raises Exception if column is already
1927-
contained in the DataFrame
1931+
1932+
If `allow_duplicates` is False, raises Exception if column
1933+
is already contained in the DataFrame.
19281934
19291935
Parameters
19301936
----------
@@ -2010,7 +2016,7 @@ def xs(self, key, axis=0, level=None, copy=True, drop_level=True):
20102016
which levels are used. Levels can be referred by label or position.
20112017
copy : boolean, default True
20122018
Whether to make a copy of the data
2013-
drop_level, default True
2019+
drop_level : boolean, default True
20142020
If False, returns object with same levels as self.
20152021
20162022
Examples
@@ -2133,9 +2139,9 @@ def xs(self, key, axis=0, level=None, copy=True, drop_level=True):
21332139
_xs = xs
21342140

21352141
def lookup(self, row_labels, col_labels):
2136-
"""Label-based "fancy indexing" function for DataFrame. Given
2137-
equal-length arrays of row and column labels, return an array of the
2138-
values corresponding to each (row, col) pair.
2142+
"""Label-based "fancy indexing" function for DataFrame.
2143+
Given equal-length arrays of row and column labels, return an
2144+
array of the values corresponding to each (row, col) pair.
21392145
21402146
Parameters
21412147
----------
@@ -2146,13 +2152,11 @@ def lookup(self, row_labels, col_labels):
21462152
21472153
Notes
21482154
-----
2149-
Akin to
2150-
2151-
.. code-block:: python
2155+
Akin to::
21522156
2153-
result = []
2154-
for row, col in zip(row_labels, col_labels):
2155-
result.append(df.get_value(row, col))
2157+
result = []
2158+
for row, col in zip(row_labels, col_labels):
2159+
result.append(df.get_value(row, col))
21562160
21572161
Examples
21582162
--------
@@ -2467,14 +2471,14 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
24672471
axis : {0, 1}, or tuple/list thereof
24682472
Pass tuple or list to drop on multiple axes
24692473
how : {'any', 'all'}
2470-
any : if any NA values are present, drop that label
2471-
all : if all values are NA, drop that label
2474+
* any : if any NA values are present, drop that label
2475+
* all : if all values are NA, drop that label
24722476
thresh : int, default None
24732477
int value : require that many non-NA values
24742478
subset : array-like
24752479
Labels along other axis to consider, e.g. if you are dropping rows
24762480
these would be a list of columns to include
2477-
inplace : bool, defalt False
2481+
inplace : boolean, defalt False
24782482
If True, do operation inplace and return None.
24792483
24802484
Returns
@@ -2725,7 +2729,7 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):
27252729
----------
27262730
level : int
27272731
axis : {0, 1}
2728-
ascending : bool, default True
2732+
ascending : boolean, default True
27292733
inplace : boolean, default False
27302734
Sort the DataFrame without creating a new instance
27312735
@@ -2790,9 +2794,11 @@ def reorder_levels(self, order, axis=0):
27902794
27912795
Parameters
27922796
----------
2793-
order: list of int representing new level order.
2794-
(reference level by number not by key)
2795-
axis: where to reorder levels
2797+
order : list of int
2798+
List representing new level order. Reference level by number
2799+
not by key.
2800+
axis : int
2801+
Where to reorder levels.
27962802
27972803
Returns
27982804
-------
@@ -3057,8 +3063,10 @@ def combine_first(self, other):
30573063
30583064
Examples
30593065
--------
3066+
a's values prioritized, use values from b to fill holes:
3067+
30603068
>>> a.combine_first(b)
3061-
a's values prioritized, use values from b to fill holes
3069+
30623070
30633071
Returns
30643072
-------
@@ -3094,7 +3102,7 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
30943102
filter_func : callable(1d-array) -> 1d-array<boolean>, default None
30953103
Can choose to replace values other than NA. Return True for values
30963104
that should be updated
3097-
raise_conflict : bool
3105+
raise_conflict : boolean
30983106
If True, will raise an error if the DataFrame and other both
30993107
contain data in the same place.
31003108
"""
@@ -3322,22 +3330,24 @@ def diff(self, periods=1):
33223330
def apply(self, func, axis=0, broadcast=False, raw=False, reduce=True,
33233331
args=(), **kwds):
33243332
"""
3325-
Applies function along input axis of DataFrame. Objects passed to
3326-
functions are Series objects having index either the DataFrame's index
3327-
(axis=0) or the columns (axis=1). Return type depends on whether passed
3328-
function aggregates
3333+
Applies function along input axis of DataFrame.
3334+
3335+
Objects passed to functions are Series objects having index
3336+
either the DataFrame's index (axis=0) or the columns (axis=1).
3337+
Return type depends on whether passed function aggregates
33293338
33303339
Parameters
33313340
----------
33323341
func : function
3333-
Function to apply to each column
3342+
Function to apply to each column/row
33343343
axis : {0, 1}
3335-
0 : apply function to each column
3336-
1 : apply function to each row
3337-
broadcast : bool, default False
3344+
* 0 : apply function to each column
3345+
* 1 : apply function to each row
3346+
broadcast : boolean, default False
33383347
For aggregation functions, return object of same size with values
33393348
propagated
3340-
reduce : bool, default True, try to apply reduction procedures
3349+
reduce : boolean, default True
3350+
Try to apply reduction procedures
33413351
raw : boolean, default False
33423352
If False, convert each row or column into a Series. If raw=True the
33433353
passed function will receive ndarray objects instead. If you are
@@ -3529,6 +3539,11 @@ def applymap(self, func):
35293539
Returns
35303540
-------
35313541
applied : DataFrame
3542+
3543+
See also
3544+
--------
3545+
DataFrame.apply : For operations on rows/columns
3546+
35323547
"""
35333548

35343549
# if we have a dtype == 'M8[ns]', provide boxed values
@@ -3611,6 +3626,7 @@ def join(self, other, on=None, how='left', lsuffix='', rsuffix='',
36113626
how : {'left', 'right', 'outer', 'inner'}
36123627
How to handle indexes of the two objects. Default: 'left'
36133628
for joining on index, None otherwise
3629+
36143630
* left: use calling frame's index
36153631
* right: use input frame's index
36163632
* outer: form union of indexes
@@ -3698,9 +3714,9 @@ def corr(self, method='pearson', min_periods=1):
36983714
Parameters
36993715
----------
37003716
method : {'pearson', 'kendall', 'spearman'}
3701-
pearson : standard correlation coefficient
3702-
kendall : Kendall Tau correlation coefficient
3703-
spearman : Spearman rank correlation
3717+
* pearson : standard correlation coefficient
3718+
* kendall : Kendall Tau correlation coefficient
3719+
* spearman : Spearman rank correlation
37043720
min_periods : int, optional
37053721
Minimum number of observations required per pair of columns
37063722
to have a valid result. Currently only available for pearson
@@ -3756,7 +3772,9 @@ def cov(self, min_periods=None):
37563772
-------
37573773
y : DataFrame
37583774
3759-
y contains the covariance matrix of the DataFrame's time series.
3775+
Notes
3776+
-----
3777+
`y` contains the covariance matrix of the DataFrame's time series.
37603778
The covariance is normalized by N-1 (unbiased estimator).
37613779
"""
37623780
numeric_df = self._get_numeric_data()
@@ -4156,9 +4174,9 @@ def mode(self, axis=0, numeric_only=False):
41564174
Parameters
41574175
----------
41584176
axis : {0, 1, 'index', 'columns'} (default 0)
4159-
0/'index' : get mode of each column
4160-
1/'columns' : get mode of each row
4161-
numeric_only : bool, default False
4177+
* 0/'index' : get mode of each column
4178+
* 1/'columns' : get mode of each row
4179+
numeric_only : boolean, default False
41624180
if True, only apply to numeric columns
41634181
41644182
Returns
@@ -4213,14 +4231,14 @@ def rank(self, axis=0, numeric_only=None, method='average',
42134231
numeric_only : boolean, default None
42144232
Include only float, int, boolean data
42154233
method : {'average', 'min', 'max', 'first'}
4216-
average: average rank of group
4217-
min: lowest rank in group
4218-
max: highest rank in group
4219-
first: ranks assigned in order they appear in the array
4234+
* average: average rank of group
4235+
* min: lowest rank in group
4236+
* max: highest rank in group
4237+
* first: ranks assigned in order they appear in the array
42204238
na_option : {'keep', 'top', 'bottom'}
4221-
keep: leave NA values where they are
4222-
top: smallest rank if ascending
4223-
bottom: smallest rank if descending
4239+
* keep: leave NA values where they are
4240+
* top: smallest rank if ascending
4241+
* bottom: smallest rank if descending
42244242
ascending : boolean, default True
42254243
False for ranks by high (1) to low (N)
42264244
@@ -4861,11 +4879,11 @@ def boxplot(self, column=None, by=None, ax=None, fontsize=None,
48614879
Can be any valid input to groupby
48624880
by : string or sequence
48634881
Column in the DataFrame to group by
4864-
ax : matplotlib axis object, default None
4882+
ax : matplotlib axis object, default None
48654883
fontsize : int or string
4866-
rot : int, default None
4884+
rot : int, default None
48674885
Rotation for ticks
4868-
grid : boolean, default None (matlab style default)
4886+
grid : boolean, default None (matlab style default)
48694887
Axis grid lines
48704888
48714889
Returns

0 commit comments

Comments
 (0)