У меня есть фрейм данных, который содержит два столбца, как показано ниже:
data = [["76895","How was your day?","767392|docu73635363","How are you doing?"],["67387|876357|58745|874512","split the line"]]
df = pd.DataFrame(data,columns=['col1','col2'])
col1 col2
0 76895 How was your day?
1 767392|docu73635363 How are you doing?
2 67387|876357|58745|874512 split the line
Я хочу разделить значение, созданное на |в две строки и удалите «document» и преобразуйте col1 в int.Желаемый вывод:
data = [["76895","How was your day?","767392","How are you doing?"],["3635363","How are you doing?"],["67387","split the line"],["876357","split the line"],["58745","split the line"],["874512","split the line"]]
df = pd.DataFrame(data,columns=['col1','col2'])
col1 col2
0 76895 How was your day?
1 767392 How are you doing?
2 3635363 How are you doing?
3 67387 split the line
4 876357 split the line
5 58745 split the line
5 874512 split the line
Моя попытка:
if "|" in df['col1']:
value = int(df['col1'].split("|")[0])