如何在 pandas 中获取索引列的名称
为了获取 pandas DataFrame 的索引列名称,使用
index_name.py
df.index.name例如,我们可以打印 TechOverflow 时间序列示例数据集 的索引列名称:
index_name_example.py
import pandas as pd
# 加载预构建的时间序列示例数据集
df = pd.read_csv("https://datasets.techoverflow.net/timeseries-example.csv", parse_dates=["Timestamp"])
df.set_index("Timestamp", inplace=True)
print(df.index.name)将打印
index_name_output.txt
TimestampIf this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow