Skip to content

Commit 171c0ec

Browse files
DriesSvladu
DriesS
authored andcommitted
DOC: Clarify DataFrame column argument in API documentation (pandas-dev#40658)
1 parent fc9f21b commit 171c0ec

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pandas/core/frame.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ 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+
Column labels to use for resulting frame when data does not have them,
476+
defaulting to RangeIndex(0, 1, 2, ..., n). If data contains column labels,
477+
will perform column selection instead.
477478
dtype : dtype, default None
478479
Data type to force. Only a single dtype is allowed. If None, infer.
479480
copy : bool or None, default None
@@ -527,6 +528,18 @@ class DataFrame(NDFrame, OpsMixin):
527528
1 4 5 6
528529
2 7 8 9
529530
531+
Constructing DataFrame from a numpy ndarray that has labeled columns:
532+
533+
>>> data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
534+
... dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")])
535+
>>> df3 = pd.DataFrame(data, columns=['c', 'a'])
536+
...
537+
>>> df3
538+
c a
539+
0 3 1
540+
1 6 4
541+
2 9 7
542+
530543
Constructing DataFrame from dataclass:
531544
532545
>>> from dataclasses import make_dataclass

0 commit comments

Comments
 (0)