Мне не удалось воспроизвести ошибку, с которой вы столкнулись. Можете ли вы подтвердить, какая версия Pandas установлена у вас?
Однако я смог добиться результатов, которые, как вы думаете, вы искали, с помощью следующего настроенного кода:
df['col_2'] = df['col_1'].apply(lambda x: int(x.split('/')[0]))
Если вы применяете это преобразование к каждой строке, df.loc [:, 'col_1'] и df ['col_1'] должны возвращать одно и то же.
Мой полный тестовый код приведен ниже:
import pandas as pd
d = {
'col_1':[
'0/Usidore',
'1/Wizard of the 12th Realm of Ephysiyies',
'2/Master of Light and Shadow',
'3/Manipulator of Magical Delights',
'4/Devourer of Chaos',
'5/Champion of the Great Halls of Terr\'akkas',
'6/elves/Fi’ang Yalok',
'7/dwarfs/Zoenen Hoogstandjes',
'8/northeast/Gaismunēnas Meistar'
]
}
df = pd.DataFrame(data = d)
df['col_2'] = df['col_1'].apply(lambda x: int(x.split('/')[0]))
df
И возвращает
col_1 col_2
0 0/Usidore 0
1 1/Wizard of the 12th Realm of Ephysiyies 1
2 2/Master of Light and Shadow 2
3 3/Manipulator of Magical Delights 3
4 4/Devourer of Chaos 4
5 5/Champion of the Great Halls of Terr'akkas 5
6 6/elves/Fi’ang Yalok 6
7 7/dwarfs/Zoenen Hoogstandjes 7
8 8/northeast/Gaismunēnas Meistar 8
Надеюсь, это поможет!