Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3842,6 +3842,12 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
necessary. Setting to False will improve the performance of this
method

See Also
--------
DataFrame.reset_index : opposite of set_index
DataFrame.reindex : change to new indices or expand indices
DataFrame.reindex_like : change to same indices as other DataFrame

Examples
--------
>>> df = pd.DataFrame({'month': [1, 4, 7, 10],
Expand Down Expand Up @@ -3981,6 +3987,12 @@ def reset_index(self, level=None, drop=False, inplace=False, col_level=0,
-------
resetted : DataFrame

See Also
--------
DataFrame.set_index : opposite of reset_index
DataFrame.reindex : change to new indices or expand indices
DataFrame.reindex_like : change to same indices as other DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you capitalize the first letter of each description, and add a period at the end please


Examples
--------
>>> df = pd.DataFrame([('bird', 389.0),
Expand Down
75 changes: 60 additions & 15 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3331,12 +3331,18 @@ def select(self, crit, axis=0):

def reindex_like(self, other, method=None, copy=True, limit=None,
tolerance=None):
"""Return an object with matching indices to myself.
"""
Return an object with matching indices as other object.

Conform the object to the same index on all axes. Optional
filling logic, placing NA/NaN in locations having no value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just say NaN

in the previous index. A new object is produced unless the
new index is equivalent to the current one and copy=False.

Parameters
----------
other : Object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess other can only be Series and DataFrame? Or can we be more specific?

method : string or None
method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}
copy : boolean, default True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, bool instead of boolean

limit : int, default None
Maximum number of consecutive labels to fill for inexact matches.
Expand All @@ -3348,12 +3354,43 @@ def reindex_like(self, other, method=None, copy=True, limit=None,

Notes
-----
Like calling s.reindex(index=other.index, columns=other.columns,
method=...)
Like calling `.reindex(index=other.index, columns=other.columns,
method=...)`

Returns
-------
reindexed : same as input
Object
same object type as input, but with changed indices on each axis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave out the "Object" line, and directly put the explanation on that line.

And can you use Capital first character and end point punctuation?


See Also
--------
DataFrame.set_index : set row labels
DataFrame.reset_index : remove row labels or move them to new columns
DataFrame.reindex : change to new indices or expand indices

Examples
--------
>>> df_weather_station_1 = pd.DataFrame([[24.3, 75.7, 'high'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the _weather_station bit adds any value; would be OK to just use df1, df2, etc...

... [31, 87.8, 'high'],
... [22, 71.6, 'medium'],
... [35, 95, 'medium']],
... columns=['temp_celsius', 'temp_fahrenheit', 'windspeed'],
... index=pd.date_range(start='2014-02-12',
... end='2014-02-15', freq='D'))

>>> df_weather_station_2 = pd.DataFrame([[28, 'low'],
... [30, 'low'],
... [35.1, 'medium']],
... columns=['temp_celsius', 'windspeed'],
... index=pd.DatetimeIndex(['2014-02-12', '2014-02-13',
... '2014-02-15']))

>>> df_weather_station_2.reindex_like(df_weather_station_1)
temp_celsius temp_fahrenheit windspeed
2014-02-12 28.0 NaN low
2014-02-13 30.0 NaN low
2014-02-14 NaN NaN NaN
2014-02-15 35.1 NaN medium
"""
d = other._construct_axes_dict(axes=self._AXIS_ORDERS, method=method,
copy=copy, limit=limit,
Expand Down Expand Up @@ -3769,6 +3806,12 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,

.. versionadded:: 0.21.0 (list-like tolerance)

See Also
--------
DataFrame.set_index : set row labels
DataFrame.reset_index : remove row labels or move them to new columns
DataFrame.reindex_like : change to same indices as other DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, capitalize and finish with periods.


Examples
--------

Expand Down Expand Up @@ -3994,11 +4037,10 @@ def _needs_reindex_multi(self, axes, method, level):
def _reindex_multi(self, axes, copy, fill_value):
return NotImplemented

_shared_docs[
'reindex_axis'] = ("""Conform input object to new index with optional
filling logic, placing NA/NaN in locations having no value in the
previous index. A new object is produced unless the new index is
equivalent to the current one and copy=False
_shared_docs['reindex_axis'] = ("""Conform input object to new index
with optional filling logic, placing NA/NaN in locations having
no value in the previous index. A new object is produced unless
the new index is equivalent to the current one and copy=False.

Parameters
----------
Expand Down Expand Up @@ -4035,17 +4077,20 @@ def _reindex_multi(self, axes, copy, fill_value):

.. versionadded:: 0.21.0 (list-like tolerance)

Examples
--------
>>> df.reindex_axis(['A', 'B', 'C'], axis=1)

See Also
--------
reindex, reindex_like
DataFrame.set_index : set row labels
DataFrame.reset_index : remove row labels or move them to new columns
DataFrame.reindex : change to new indices or expand indices
DataFrame.reindex_like : change to same indices as other DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you capitalize and finish with period these descriptions.


Returns
-------
reindexed : %(klass)s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reindexed : %(klass)s
%(klass)s

And add a short description of what is being returned in the next line.


Examples
--------
>>> df.reindex_axis(['A', 'B', 'C'], axis=1)
""")

@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
Expand Down