diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 46501c97cf38a..60eb0339b1f1d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -472,8 +472,9 @@ class DataFrame(NDFrame, OpsMixin): Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided. columns : Index or array-like - Column labels to use for resulting frame. Will default to - RangeIndex (0, 1, 2, ..., n) if no column labels are provided. + Column labels to use for resulting frame when data does not have them, + defaulting to RangeIndex(0, 1, 2, ..., n). If data contains column labels, + will perform column selection instead. dtype : dtype, default None Data type to force. Only a single dtype is allowed. If None, infer. copy : bool, default False @@ -523,6 +524,18 @@ class DataFrame(NDFrame, OpsMixin): 1 4 5 6 2 7 8 9 + Constructing DataFrame from a numpy ndarray that has labeled columns: + + >>> data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)], + ... dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")]) + >>> df3 = pd.DataFrame(data, columns=['c', 'a']) + ... + >>> df3 + c a + 0 3 1 + 1 6 4 + 2 9 7 + Constructing DataFrame from dataclass: >>> from dataclasses import make_dataclass