Answers for "new column from dictionary pandas"

1

create new column using dictionary padnas

U
111
112
112

d = {112: 'a', 111: 'b'}
df['B'] = df['A'].map(d)
df
Out[248]:
     A    B
0  111    a
1  112    b
Posted by: Guest on March-22-2021
0

creating new column with dictionary

In [248]:
dict_ = {112: 'en', 113: 'es', 114: 'es', 111: 'en'}
df['D'] = df['U'].map(dict_)
df

Out[248]:
     U   L   D
0  111  en  en
1  112  en  en
2  112  es  en
3  113  es  es
4  113  ja  es
5  113  zh  es
6  114  es  es
Posted by: Guest on September-23-2021

Code answers related to "new column from dictionary pandas"

Python Answers by Framework

Browse Popular Code Answers by Language