Skip to content

Commit 101c10c

Browse files
DOC: #39904: Clarify DataFrame column argument in API documentation.
1 parent 7c71498 commit 101c10c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pandas/core/frame.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,12 @@ class DataFrame(NDFrame, OpsMixin):
472472
Index to use for resulting frame. Will default to RangeIndex if
473473
no indexing information part of input data and no index provided.
474474
columns : Index or array-like
475-
Column labels to use for resulting frame. Will default to
476-
RangeIndex (0, 1, 2, ..., n) if no column labels are provided.
475+
Columns to select from data or column labels to use for resulting frame.
476+
Will use the provided labels for the column index if data does not
477+
include column labels, defaulting to RangeIndex(0, 1, 2, ..., n).
478+
If data does include column labels, will select the columns from data matching
479+
with the provided labels to include in the frame, defaulting to
480+
all columns.
477481
dtype : dtype, default None
478482
Data type to force. Only a single dtype is allowed. If None, infer.
479483
copy : bool, default False
@@ -523,6 +527,16 @@ class DataFrame(NDFrame, OpsMixin):
523527
1 4 5 6
524528
2 7 8 9
525529
530+
>>> d = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
531+
... dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")])
532+
>>> df3 = pd.DataFrame(d, columns=['c', 'a'])
533+
...
534+
>>> df3
535+
c a
536+
0 3 1
537+
1 6 4
538+
2 9 7
539+
526540
Constructing DataFrame from dataclass:
527541
528542
>>> from dataclasses import make_dataclass

0 commit comments

Comments
 (0)