要重新指定行索引,可以使用set_index()方法。以下是一个示例:

import pandas as pd

# 创建示例数据框
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

# 重新指定行索引
df = df.set_index('A')

print(df)

输出:

   B
A   
1  4
2  5
3  6

在上述示例中,我们使用set_index('A')将列'A'作为新的行索引。

一个已经读取的data frame 如何重新指定行index

原文地址: https://www.cveoy.top/t/topic/imRQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录