环境信息
- ModelArts
- Notebook - Multi-Engine 2.0 (python3)
- JupyterLab - Notebook - Conda-python3
Pandas DataFrame reset_index 合并数据后,重新设置索引
import pandas as pd
import numpy as np
df_top = pd.DataFrame(np.ones((3,2)))
df_bottom = pd.DataFrame(np.zeros((3,2)))
df_top

df_bottom

new_df = pd.concat([df_top,df_bottom])
new_df

new_df.reset_index(drop=True)

new_df.reset_index(drop=False)

new_df = pd.concat([df_top,df_bottom]).reset_index(drop=False)
new_df

help
help(new_df.reset_index)
Help on method reset_index in module pandas.core.frame:
reset_index(level=None, drop=False, inplace=False, col_level=0, col_fill='') method of pandas.core.frame.DataFrame instance
For DataFrame with multi-level index, return new DataFrame with
labeling information in the columns under the index names, defaulting
to 'level_0', 'level_1', etc. if any are None. For a standard index,
the index name will be used (if set), otherwise a default 'index' or
'level_0' (if 'index' is already taken) will be used.
......
备注
- 欢迎各位同学一起来交流学习心得^_^
- 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
(完)