我一直在探索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