-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
[DOCS] Add example of how to preserve order of columns with usecols. #19746
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19746 +/- ##
==========================================
+ Coverage 91.58% 91.6% +0.02%
==========================================
Files 150 150
Lines 48862 48864 +2
==========================================
+ Hits 44750 44763 +13
+ Misses 4112 4101 -11
Continue to review full report at Codecov.
|
doc/source/io.rst
Outdated
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. | ||
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. Element | ||
order is ignored, so usecols=[1,0] is the same as [0,1]. To instantiate a | ||
DataFrame with element order preserved use ``pd.read_csv(usecols=[0, 1])[[0, 1]]`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be “pd.read_csv(usecols=[0, 1])[[1, 0]]”
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that. Fixed in commit f137bd0
doc/source/io.rst
Outdated
@@ -136,7 +136,11 @@ usecols : array-like or callable, default ``None`` | |||
that correspond to column names provided either by the user in `names` or | |||
inferred from the document header row(s). For example, a valid array-like | |||
`usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``. | |||
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. | |||
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. Element | |||
order is ignored, so usecols=[1,0] is the same as [0,1]. To instantiate a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put these usecols=[]
in double back ticks as well? And commas between the elements.
Finally, I have a slight preference for using names like ['foo', 'bar']
instead of [0, 1]
, even though it's a bit longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Please refer to f137bd0
I went ahead and encased usecols in double back ticks.
Updated column names per your suggestion. I was originally trying to keep consistent with the line before Element order is ignored, so usecols=[0, 1]
is the same as [1, 0]
.
Hello @EricChea! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 18, 2018 at 18:27 Hours UTC |
…mes from numeric to string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small change otherwise lgtm.
doc/source/io.rst
Outdated
@@ -136,7 +136,12 @@ usecols : array-like or callable, default ``None`` | |||
that correspond to column names provided either by the user in `names` or | |||
inferred from the document header row(s). For example, a valid array-like | |||
`usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``. | |||
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a blank line before the additions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. Please refer to 68efc4b
ping @jreback @jorisvandenbossche : this is green and ready to merge |
Thanks @EricChea! |
Thanks for reviewing @TomAugspurger |
…andas-dev#19746) * Add example of how to preserve order of columns with usecols. * Encase usecols in double back ticks for consistency. Change column names from numeric to string. * Add line to separate examples.
What's this PR do?
Adding an example of how to preserve order when using the
usecols
parameter. I've noticed that some folks are still unaware that the columns will not necessarily be returned in the specified order passed tousecols
.