diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 743d623ee5e44..907959c42323e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -241,17 +241,47 @@ class DataFrame(NDFrame): Column labels to use for resulting frame. Will default to np.arange(n) if no column labels are provided dtype : dtype, default None - Data type to force, otherwise infer + Data type to force. Only a single dtype is allowed. If None, infer copy : boolean, default False Copy data from inputs. Only affects DataFrame / 2d ndarray input Examples -------- - >>> d = {'col1': ts1, 'col2': ts2} - >>> df = DataFrame(data=d, index=index) - >>> df2 = DataFrame(np.random.randn(10, 5)) - >>> df3 = DataFrame(np.random.randn(10, 5), - ... columns=['a', 'b', 'c', 'd', 'e']) + Constructing DataFrame from a dictionary. + + >>> d = {'col1': [1, 2], 'col2': [3, 4]} + >>> df = pd.DataFrame(data=d) + >>> df + col1 col2 + 0 1 3 + 1 2 4 + + Notice that the inferred dtype is int64. + + >>> df.dtypes + col1 int64 + col2 int64 + dtype: object + + To enforce a single dtype: + + >>> df = pd.DataFrame(data=d, dtype=np.int8) + >>> df.dtypes + col1 int8 + col2 int8 + dtype: object + + Constructing DataFrame from numpy ndarray: + + >>> df2 = pd.DataFrame(np.random.randint(low=0, high=10, size=(5, 5)), + ... columns=['a', 'b', 'c', 'd', 'e']) + >>> df2 + a b c d e + 0 2 8 8 3 4 + 1 4 2 9 0 9 + 2 1 0 7 8 0 + 3 5 1 7 1 3 + 4 6 0 2 4 2 See also --------