pandas筛选完数据后pandas如何取消原先的index
时间: 2023-10-13 13:17:14 浏览: 204
可以使用reset_index()函数来取消原先的index,例如:
```
import pandas as pd
# 创建一个DataFrame
df = pd.DataFrame({'name': ['Tom', 'Jerry', 'Mike'], 'age':[20, 22, 30], 'city':['Beijing', 'Shanghai', 'Guangzhou']})
# 筛选age大于等于22的数据
df_filtered = df[df['age']>=22]
# 取消原先的index
df_filtered = df_filtered.reset_index(drop=True)
print(df_filtered)
```
输出结果:
```
name age city
0 Jerry 22 Shanghai
1 Mike 30 Guangzhou
```
阅读全文