Note

Pandas (50) 본문

Pandas

Pandas (50)

알 수 없는 사용자 2022. 9. 16. 13:58
728x90

How to create a primary key index by combining relevant columns?

# Input
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv', usecols=[0,1,2,3,5])

# Solution
df[['Manufacturer', 'Model', 'Type']] = df[['Manufacturer', 'Model', 'Type']].fillna('missing')
df.index = df.Manufacturer + '_' + df.Model + '_' + df.Type
print(df.index.is_unique)

# output
True

 

'Pandas' 카테고리의 다른 글

Pandas (53)  (0) 2022.09.20
Pandas (51)  (1) 2022.09.17
Pandas (49)  (0) 2022.09.15
Pandas (48)  (0) 2022.09.14
Pandas (47)  (0) 2022.09.13
Comments