Skip to content

DOC:Improve the docstring of DataFrame.iloc() #20228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 7, 2018
32 changes: 30 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,8 @@ def _getitem_axis(self, key, axis=None):


class _iLocIndexer(_LocationIndexer):
"""Purely integer-location based indexing for selection by position.
"""
Purely integer-location based indexing for selection by position.

``.iloc[]`` is primarily integer position based (from ``0`` to
``length-1`` of the axis), but may also be used with a boolean
Expand All @@ -1648,8 +1649,35 @@ class _iLocIndexer(_LocationIndexer):
out-of-bounds, except *slice* indexers which allow out-of-bounds
indexing (this conforms with python/numpy *slice* semantics).

See more at :ref:`Selection by Position <indexing.integer>`
See Also
--------
DataFrame.ix : A primarily label-location based indexer
Copy link
Contributor

Choose a reason for hiding this comment

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

ix is deprecated, you can remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

DataFrame.loc : Fast integer location scalar accessor.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you may want the " A primarily label-location based indexer" for the .loc description.

You may be thinking of DataFrame.iat for this dsecription.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove ix and update loc description:

  • DataFrame.ix : A primarily label-location based indexer
  • DataFrame.loc : Fast integer location scalar accessor.
  • DataFrame.iat : Fast integer location scalar accessor.
  • DataFrame.loc : Purely label-location based indexer for selection by label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

missed your comment about .loc .. but instead got the description from https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html


Examples
--------
>>> import pandas as pd
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need the pandas import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed pandas import

>>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
... {'a': 100, 'b': 200, 'c': 300, 'd': 400},
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP8: single spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the double spaces with single

... {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
>>> df = pd.DataFrame(mydict)
>>> print(df.head())
a b c d
0 1 2 3 4
1 100 200 300 400
2 1000 2000 3000 4000
>>> print(df.iloc[0])
a 1
b 2
c 3
d 4
Name: 0, dtype: int64
>>> print(df.iloc[0:2])
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need the prints here and above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

took off the prints

a b c d
0 1 2 3 4
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting seems a bit off. Can you double check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reran the command and updated.

1 100 200 300 400

ref:`Selection by Position <indexing.integer>`
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use the "extended summary" section for this, right below the opening summary? I think the prose docs are the most important for indexing, and I don't want them to get lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved it to "extended summary"

"""

_valid_types = ("integer, integer slice (START point is INCLUDED, END "
Expand Down