pandas --index ,reindex, set_index, reset_index , reindex_like函数 之 reset_index


reset_index(
    level: Union[Hashable, Sequence[Hashable], NoneType] = None,
    drop: bool = False,
    inplace: bool = False,
    col_level: Hashable = 0,
    col_fill: Union[Hashable, NoneType] = '',
) -> Union[ForwardRef('DataFrame'), NoneType]
Docstring:
Reset the index, or a level of it.

Reset the index of the DataFrame, and use the default one instead.
If the DataFrame has a MultiIndex, this method can remove one or more
levels.

Parameters
----------
level : int, str, tuple, or list, default None
    Only remove the given levels from the index. Removes all levels by
    default.
drop : bool, default False
    Do not try to insert index into dataframe columns. This resets
    the index to the default integer index.
inplace : bool, default False
    Modify the DataFrame in place (do not create a new object).
col_level : int or str, default 0
    If the columns have multiple levels, determines which level the
    labels are inserted into. By default it is inserted into the first
    level.
col_fill : object, default ''
    If the columns have multiple levels, determines how the other
    levels are named. If None then the index name is repeated.

Returns
-------
DataFrame or None
    DataFrame with the new index or None if ``inplace=True``.

reset_index()

  • 函数原型:DataFrame.reset_index(level=None, drop=False, inplace=False, col_level=0, col_fill='')
  • 参数解释:
    level:int、str、tuple或list,默认无,仅从索引中删除给定级别。默认情况下移除所有级别。控制了具体要还原的那个等级的索引
    drop:drop为False则索引列会被还原为普通列,否则会丢失
    inplace:默认为false,适当修改DataFrame(不要创建新对象)
    col_level:int或str,默认值为0,如果列有多个级别,则确定将标签插入到哪个级别。默认情况下,它将插入到第一级。
    col_fill:对象,默认‘’,如果列有多个级别,则确定其他级别的命名方式。如果没有,则重复索引名
  • 注:reset_index还原分为两种类型,第一种是对原DataFrame进行reset,第二种是对使用过set_index()函数的DataFrame进行reset



原文地址:https://www.cnblogs.com/vincent-sh/p/12861608.html