我有这个Python字典:
dictionary = {
'1':'A',
'2':'B',
'3':'C',
'4':'D',
'5':'E',
'6':'F',
'7':'G',
'8':'H',
'8':'I',
'9':'J',
'0':'L'
}
我已创建了这个简单的pandas数据框:
import pandas as pd
ds = {'col1' : [12345,67890], 'col2' : [12364,78910]}
df = pd.DataFrame(data=ds)
print(df)
它长这样:
col1 col2
0 12345 12364
1 67890 78910
我希望将
col1
中的每个数字(它是一个int
字段)转换为上述字典中指定的对应字母。因此,基本上我希望生成的数据框如下所示: col1 col2 col1_transformed
0 12345 12364 ABCDE
1 67890 78910 FGHIJ
有没有一种快速、Pythonic的方法可以做到这一点呢?