Skip to content

Commit 4131149

Browse files
stijnvanhoeyjorisvandenbossche
authored andcommitted
DOC: Extend docstring pandas core index to_frame method (#20036)
1 parent 52cffa3 commit 4131149

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pandas/core/indexes/base.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,26 @@ def to_frame(self, index=True):
11481148
11491149
Returns
11501150
-------
1151-
DataFrame : a DataFrame containing the original Index data.
1151+
DataFrame
1152+
DataFrame containing the original Index data.
1153+
1154+
Examples
1155+
--------
1156+
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
1157+
>>> idx.to_frame()
1158+
animal
1159+
animal
1160+
Ant Ant
1161+
Bear Bear
1162+
Cow Cow
1163+
1164+
By default, the original Index is reused. To enforce a new Index:
1165+
1166+
>>> idx.to_frame(index=False)
1167+
animal
1168+
0 Ant
1169+
1 Bear
1170+
2 Cow
11521171
"""
11531172

11541173
from pandas import DataFrame

0 commit comments

Comments
 (0)