Я создал фрейм данных с помощью словаря, теперь я хочу разделить 2 столбца в фрейме данных на 4 столбца.
Изначально во фрейме данных есть 3 столбца, т. Е. Родитель, потомок и счет. Я хочу разделить столбец «Родитель» на столбцы «col1 и col2» и «Дочерний» на столбцы «col3 и col4» и разделить его с помощью разделителя '+'
Я попробовал некоторые из следующих методов, может помочь любой из них
def request_service(Sentence,id):
dict_ip = {"id": "2018 Regression", "Sentence": "What is the customers Issue/problem? Customer spoke to our mobile banking help
payload = json.dumps(dict_ip)
print(payload)
response = requests.request("POST", url, data=payload, headers=headers)
dict_list = json.loads(response.text)
print(dict_list)
#dict_list = {'results': [{'Parent': 'A+B', 'child': 'C+D', 'score': 0.36283498590263946}, {'Parent': 'D+E', 'child': 'A+B', 'score': 0.10505374311256221}, {'Parent': 'N+M', 'child': 'Q+R', 'score': 0.09593593898873307}]}
df_op = pd.DataFrame(columns=['Parent', 'Child', 'Score'])
for idx, result in enumerate(dict_list['results']):
df_op.loc[idx] = [result['Parent'], result['child'], result['score']]
df_op.Score = df_op.Score.round(2)
return df_op
Ожидаемый вывод - Datframe с 5 столбцами
col1 col2 col3 col4 Score
A B C D 0.36
D E A B 0.10
N M Q R 0.09