【发布时间】:2017-08-23 12:44:28
【问题描述】:
pandas 中是否有一种方法可以为 pandas 数据框的同一列提供两个名称,以便我可以仅通过这两个名称中的一个来索引该列?这是一个说明我的问题的简单示例:
import pandas as pd
index=['a','b','c','d']
# The list of tuples here is really just to
# somehow visualize my problem below:
columns = [('A','B'), ('C','D'),('E','F')]
df = pd.DataFrame(index=index, columns=columns)
# I can index like that:
df[('A','B')]
# But I would like to be able to index like this:
df[('A',*)] #error
df[(*,'B')] #error
【问题讨论】:
标签: python-3.x pandas dataframe