Index.to_frame(self, index=True, name=None)
[source]
Create a DataFrame with a column containing the Index.
New in version 0.24.0.
Parameters: |
|
---|---|
Returns: |
|
See also
Index.to_series
Series.to_frame
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal animal Ant Ant Bear Bear Cow Cow
By default, the original Index is reused. To enforce a new Index:
>>> idx.to_frame(index=False) animal 0 Ant 1 Bear 2 Cow
To override the name of the resulting column, specify name
:
>>> idx.to_frame(index=False, name='zoo') zoo 0 Ant 1 Bear 2 Cow
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.Index.to_frame.html