@@ -1228,8 +1228,8 @@ def from_dict(cls, data, orient="columns", dtype=None, columns=None) -> "DataFra
1228
1228
1229
1229
See Also
1230
1230
--------
1231
- DataFrame.from_records : DataFrame from ndarray (structured
1232
- dtype), list of tuples, dict , or DataFrame.
1231
+ DataFrame.from_records : DataFrame from structured ndarray, sequence
1232
+ of tuples or dicts , or DataFrame.
1233
1233
DataFrame : DataFrame object creation using constructor.
1234
1234
1235
1235
Examples
@@ -1628,9 +1628,13 @@ def from_records(
1628
1628
"""
1629
1629
Convert structured or record ndarray to DataFrame.
1630
1630
1631
+ Creates a DataFrame object from a structured ndarray, sequence of
1632
+ tuples or dicts, or DataFrame.
1633
+
1631
1634
Parameters
1632
1635
----------
1633
- data : ndarray (structured dtype), list of tuples, dict, or DataFrame
1636
+ data : structured ndarray, sequence of tuples or dicts, or DataFrame
1637
+ Structured input data.
1634
1638
index : str, list of fields, array-like
1635
1639
Field of array to use as the index, alternately a specific set of
1636
1640
input labels to use.
@@ -1651,6 +1655,47 @@ def from_records(
1651
1655
Returns
1652
1656
-------
1653
1657
DataFrame
1658
+
1659
+ See Also
1660
+ --------
1661
+ DataFrame.from_dict : DataFrame from dict of array-like or dicts.
1662
+ DataFrame : DataFrame object creation using constructor.
1663
+
1664
+ Examples
1665
+ --------
1666
+ Data can be provided as a structured ndarray:
1667
+
1668
+ >>> data = np.array([(3, 'a'), (2, 'b'), (1, 'c'), (0, 'd')],
1669
+ ... dtype=[('col_1', 'i4'), ('col_2', 'U1')])
1670
+ >>> pd.DataFrame.from_records(data)
1671
+ col_1 col_2
1672
+ 0 3 a
1673
+ 1 2 b
1674
+ 2 1 c
1675
+ 3 0 d
1676
+
1677
+ Data can be provided as a list of dicts:
1678
+
1679
+ >>> data = [{'col_1': 3, 'col_2': 'a'},
1680
+ ... {'col_1': 2, 'col_2': 'b'},
1681
+ ... {'col_1': 1, 'col_2': 'c'},
1682
+ ... {'col_1': 0, 'col_2': 'd'}]
1683
+ >>> pd.DataFrame.from_records(data)
1684
+ col_1 col_2
1685
+ 0 3 a
1686
+ 1 2 b
1687
+ 2 1 c
1688
+ 3 0 d
1689
+
1690
+ Data can be provided as a list of tuples with corresponding columns:
1691
+
1692
+ >>> data = [(3, 'a'), (2, 'b'), (1, 'c'), (0, 'd')]
1693
+ >>> pd.DataFrame.from_records(data, columns=['col_1', 'col_2'])
1694
+ col_1 col_2
1695
+ 0 3 a
1696
+ 1 2 b
1697
+ 2 1 c
1698
+ 3 0 d
1654
1699
"""
1655
1700
# Make a copy of the input columns so we can modify it
1656
1701
if columns is not None :
0 commit comments