我一直在探索titanic dataset。我试图创建一个 dataframe
这将有两个单独列中的泰坦尼克号沉没的人以及那些没有的人的年龄。python,pandas:创建数据帧时InvalidIndexError
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
whole = pd.concat([train, test])
df = pd.DataFrame({'survived': whole['Age'][whole['Survived'] == 1],
'died': whole['Age'][whole['Survived'] == 0]})
但我收到此错误
pandas.indexes.base.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
我在做什么错?
它运行这种变化不会对大熊猫0.20.1错误。 – ayhan
改变这个:'whole = pd.concat([train,test])'''whole = pd.concat([train,test])。reset_index(drop = True)' – Nain
@Nain是的,它工作。你能解释什么是问题吗? – Sounak