-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Could you put these Finally, I have a slight preference for using names like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching that. Fixed in commit f137bd0 |
||
for columns in ``[1, 0]`` order or ``pd.read_csv(usecols=[0, 1])[[0, 1]]`` | ||
for ``[0, 1]`` order. | ||
|
||
If callable, the callable function will be evaluated against the column names, | ||
returning names where the callable function evaluates to True: | ||
|
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