简体   繁体   English

append dataframe 将新数据添加到现有列

[英]append dataframe to add new data to existing column

I'am writing a code that requires appending a dataframe to include the new data to a specific column我正在编写一个需要附加 dataframe 以将新数据包含到特定列的代码

Here is an extract of the code as below, I'am trying to append dataframe (df), with new data(N) to column name(NAME).下面是代码的摘录,我正在尝试 append dataframe(df),将新数据(N)添加到列名(NAME)。

Names = driver.find_elements_by_class_name('section-result-title')
    for Name in Names:
       N=Name.text
       df = df.append(N, columns=['Name'])

Please advise how to amend the code to produce the required result.请告知如何修改代码以产生所需的结果。

if you want add new column to df, you can try this:如果你想向 df 添加新列,你可以试试这个:

name_list = map(lambda name: name.text(), Names)
df['Name'] = name_list

you must make sure the length of name_list is equal to df.shape[0]您必须确保name_list的长度等于df.shape[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM