gpt4 book ai didi

Python - 如何将 Panda 中的元素从列表转换为字符串

转载 作者:行者123 更新时间:2023-12-01 00:03:15 24 4
gpt4 key购买 nike

我的 df 需要原始文本,但我得到的结果位于括号内。

这是我的代码:

    chatroom = driver.find_element_by_class_name('_1_q7u')
pos= 0
df = pd.DataFrame(columns=['Msgs','Time'], index=None)
chat = driver.find_element_by_class_name('_19vo_').text
for ol in chatroom.find_elements_by_class_name('message-in'):
msgs = [k.text for k in ol.find_elements_by_class_name('_12pGw')]
times = [k.text for k in ol.find_elements_by_class_name('_1RNhZ')]
# df = [msgs,times]
df.loc[pos] = [msgs, times]
pos+=1
print(df)

这是我的输出:

       Msgs     Time
0 [T] [14:30]
1 [Z] [14:36]
2 [Q] [14:37]
3 [R] [14:39]

这是我想要的输出:

       Msgs     Time
0 T 14:30
1 Z 14:36
2 Q 14:37
3 R 14:39

最佳答案

chatroom = driver.find_element_by_class_name('_1_q7u')
pos= 0
df = pd.DataFrame(columns=['Msgs','Time'], index=None)
chat = driver.find_element_by_class_name('_19vo_').text
for ol in chatroom.find_elements_by_class_name('message-in'):
msgs = [k.text for k in ol.find_elements_by_class_name('_12pGw')][0]
times = [k.text for k in ol.find_elements_by_class_name('_1RNhZ')][0]
# df = [msgs,times]
df.loc[pos] = [msgs, times]
pos+=1
print(df)

关于Python - 如何将 Panda 中的元素从列表转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60175815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com