A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/pandas-docs/stable/reference/api/../api/pandas.Index.to_frame.html below:

pandas.Index.to_frame — pandas 2.3.1 documentation

pandas.Index.to_frame#
Index.to_frame(index=True, name=<no_default>)[source]#

Create a DataFrame with a column containing the Index.

Parameters:
indexbool, default True

Set the index of the returned DataFrame as the original Index.

nameobject, defaults to index.name

The passed name should substitute for the index name (if it has one).

Returns:
DataFrame

DataFrame containing the original Index data.

Examples

>>> 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4