-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Added paragraph on creating DataFrame from list of namedtuples #35507
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
Changes from 2 commits
d7d5f60
6c2e4fa
65edbc2
23ab74c
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 |
---|---|---|
|
@@ -397,6 +397,32 @@ The result will be a DataFrame with the same index as the input Series, and | |
with one column whose name is the original name of the Series (only if no other | ||
column name provided). | ||
|
||
|
||
.. _basics.dataframe.from_list_namedtuples: | ||
|
||
From a list of namedtuples | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The field names of the first ``namedtuple`` in the list determine the columns | ||
of the ``DataFrame``. The remaining namedtuples (or tuples) are simply unpacked | ||
and their values are fed into the rows of the ``DataFrame``. If any of those | ||
tuples is shorter than the first ``namedtuple`` then the later columns in the | ||
corresponding row are marked as missing values. If any are longer than the | ||
first ``namedtuple``, a ``ValueError`` is raised. | ||
|
||
.. ipython:: python | ||
|
||
from collections import namedtuple | ||
|
||
Point = namedtuple('Point', 'x y') | ||
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. also indent problem |
||
|
||
pd.DataFrame([Point(0, 0), Point(0, 3), (2, 3)]) | ||
|
||
Point3D = namedtuple('Point3D', 'x y z') | ||
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. also indent problem |
||
|
||
pd.DataFrame([Point3D(0, 0, 0), Point3D(0, 3, 5), Point(2, 3)]) | ||
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. also indent problem |
||
|
||
|
||
.. _basics.dataframe.from_list_dataclasses: | ||
|
||
From a list of dataclasses | ||
|
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.
CI Checks report a problem with the indent here