Adding a new column basis values from dictionary - Python Snippets - Snipit

PHOTO EMBED

Sun Jul 10 2022 05:49:34 GMT+0000 (Coordinated Universal Time)

Saved by @nilotpalc #python

# Create the dictionary containing the data of the new column
col_dict = {'Samsung': 'Lee kun-hee', 'Huawei': 'Xu Zhijun',
            'Apple': 'Tim Cook', 'Oppo': 'Tony Chen', 'Vivo': 'Shen Wei'}

# Assign the values of the dictionary as the values of the new column
df['Current chairperson'] = col_dict.values()
df

'''
Please remember that the number of values in the list should equal the numbers of rows in the pandas dataframe
'''
content_copyCOPY

https://snipit.io/