-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
DOC: Update to docstring of DataFrame(dtype) (#14764) #16487
Changes from 3 commits
b1b51ba
9ea8c0d
ccbbad6
7f6b7f4
f8435fa
6108d69
edc1c04
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 |
---|---|---|
|
@@ -241,17 +241,52 @@ 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), | ||
Constructing DataFrame from a dictionary. | ||
|
||
>>> d = {'col1': [1, 2], 'col2': [1, 2]} | ||
>>> df = 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 = DataFrame(data=d, dtype=np.int8) | ||
>>> df.dtypes | ||
col1 int8 | ||
col2 int8 | ||
dtype: object | ||
|
||
Constructing DataFrame from numpy ndarray: | ||
|
||
>>> df2 = DataFrame(np.random.randn(10, 5), | ||
... columns=['a', 'b', 'c', 'd', 'e']) | ||
>>> df2 | ||
a b c d e | ||
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. these are not lined up, something odd going on. 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. 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. can you line up on the decimals. 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. sure I'll just change the example to something easier with integers to take up less space anyway. |
||
0 -0.783492 0.563675 -0.864924 0.391128 0.353971 | ||
1 1.254319 0.375264 0.592395 -0.573814 0.093112 | ||
2 -0.548918 0.334120 0.263741 0.007451 0.536851 | ||
3 -1.266109 0.472464 0.605991 0.183181 1.605140 | ||
4 -0.136033 -1.540123 -0.625398 -1.113922 -0.314596 | ||
5 0.497200 -0.793684 -1.077530 0.015950 1.194512 | ||
6 0.074891 -0.356493 1.094723 -0.695969 -0.318360 | ||
7 0.507182 -1.311427 -0.479544 -0.825982 -1.013853 | ||
8 -0.379124 -1.314563 -0.824940 0.587772 1.334155 | ||
9 0.389357 -1.399791 -1.498242 -0.312420 0.533206 | ||
|
||
See also | ||
-------- | ||
|
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.
this is not right. you can pass a dict of dtypes.
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.
Oh interesting. How? This does not work for me:
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.
According to #4464 and #9133 it seems like this is not yet implemented.
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.
#13375 implemented his for astype
hasn't been implemented for construction