tml)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.from_dict  #

_ classmethod  _ DataFrame.  from_dict  (  _ data  _ , _ orient  =  'columns'
_ , _ dtype  =  None  _ , _ columns  =  None  _ )  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L1805-L1931) #

    

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

    

Of the form {field : array-like} or {field : dict}.

**orient** {âcolumnsâ, âindexâ, âtightâ}, 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â. If âtightâ, assume
a dict with keys [âindexâ, âcolumnsâ, âdataâ, âindex_namesâ,
âcolumn_namesâ].

New in version 1.4.0:  âtightâ as an allowed value for the ` orient  `
argument

**dtype** dtype, default None

    

Data type to force after DataFrame construction, otherwise infer.

**columns** list, default None

    

Column labels to use when ` orient='index'  ` . Raises a ValueError if used
with ` orient='columns'  ` or ` orient='tight'  ` .

Returns  :

    

DataFrame

    

See also

[ ` DataFrame.from_records  `
](pandas.DataFrame.from_records.html#pandas.DataFrame.from_records
"pandas.DataFrame.from_records")

    

DataFrame from structured ndarray, sequence of tuples or dicts, or DataFrame.

[ ` DataFrame  ` ](pandas.DataFrame.html#pandas.DataFrame "pandas.DataFrame")

    

DataFrame object creation using constructor.

[ ` DataFrame.to_dict  `
](pandas.DataFrame.to_dict.html#pandas.DataFrame.to_dict
"pandas.DataFrame.to_dict")

    

Convert the DataFrame to a dictionary.

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']}
    >>> 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
    

Specify ` orient='tight'  ` to create the DataFrame using a âtightâ
format:

    
    
    >>> data = {'index': [('a', 'b'), ('a', 'c')],
    ...         'columns': [('x', 1), ('y', 2)],
    ...         'data': [[1, 3], [2, 4]],
    ...         'index_names': ['n1', 'n2'],
    ...         'column_names': ['z1', 'z2']}
    >>> pd.DataFrame.from_dict(data, orient='tight')
    z1     x  y
    z2     1  2
    n1 n2
    a  b   1  3
       c   2  4
    

[ __ previous  pandas.DataFrame.sparse.to_dense
](pandas.DataFrame.sparse.to_dense.html "previous page") [ next
pandas.DataFrame.from_records  __ ](pandas.DataFrame.from_records.html "next
page")

__ On this page

  * ` DataFrame.from_dict()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.from_dict.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sph