-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 the docstring of pandas.DataFrame.from_dict #20259
Merged
jorisvandenbossche
merged 7 commits into
pandas-dev:master
from
dcanones:sprint_madrid_dataframe_from_dict
Mar 11, 2018
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
185ed0b
DOC: update the docstring of pandas.DataFrame.from_dict
a7b4191
PEP-8 Fixing
978d577
DOC: update the docstring of pandas.DataFrame.from_dict
4f884a6
DOC: update the docstring of pandas.DataFrame.from_dict
9caaadd
small update
jorisvandenbossche 29beaa1
pep8
jorisvandenbossche b07d9fb
pep8
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -883,27 +883,66 @@ def dot(self, other): | |
@classmethod | ||
def from_dict(cls, data, orient='columns', dtype=None, columns=None): | ||
""" | ||
Construct DataFrame from dict of array-like or dicts | ||
Construct DataFrame from dict of array-like or dicts. | ||
|
||
Creates DataFrame object from dictionary by columns or by index | ||
allowing dtype specification. | ||
|
||
Parameters | ||
---------- | ||
data : dict | ||
{field : array-like} or {field : dict} | ||
Of the form {field : array-like} or {field : dict}. | ||
orient : {'columns', 'index'}, default 'columns' | ||
The "orientation" of the data. If the keys of the passed dict | ||
should be the columns of the resulting DataFrame, pass 'columns' | ||
(default). Otherwise if the keys should be rows, pass 'index'. | ||
dtype : dtype, default None | ||
Data type to force, otherwise infer | ||
columns: list, default None | ||
Column labels to use when orient='index'. Raises a ValueError | ||
if used with orient='columns' | ||
Data type to force, otherwise infer. | ||
columns : list, default None | ||
Column labels to use when ``orient='index'``. Raises a ValueError | ||
if used with ``orient='columns'``. | ||
|
||
.. versionadded:: 0.23.0 | ||
|
||
Returns | ||
------- | ||
DataFrame | ||
pandas.DataFrame | ||
|
||
See Also | ||
-------- | ||
pandas.DataFrame.from_records : DataFrame from ndarray (structured | ||
dtype), list of tuples, dict, or DataFrame | ||
pandas.DataFrame: DataFrame object creation using constructor | ||
|
||
Examples | ||
-------- | ||
By default the keys of the dict become the DataFrame columns: | ||
|
||
>>> data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']} | ||
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 put above this example a sentence like "By default the keys of the dict become the DataFrame columns:" and then before the next example something like "Specify |
||
>>> pd.DataFrame.from_dict(data) | ||
col_1 col_2 | ||
0 3 a | ||
1 2 b | ||
2 1 c | ||
3 0 d | ||
|
||
Specify ``orient='index'`` to create the DataFrame using dictionary | ||
keys as rows: | ||
|
||
>>> data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']} | ||
>>> pd.DataFrame.from_dict(data, orient='index') | ||
0 1 2 3 | ||
row_1 3 2 1 0 | ||
row_2 a b c d | ||
|
||
When using the 'index' orientation, the column names can be | ||
specified manually: | ||
|
||
>>> pd.DataFrame.from_dict(data, orient='index', | ||
... columns=['A', 'B', 'C', 'D']) | ||
A B C D | ||
row_1 3 2 1 0 | ||
row_2 a b c d | ||
""" | ||
index = None | ||
orient = orient.lower() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DataFrame is ok here