简体   繁体   中英

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

Here is an extract of the code as below, I'am trying to append dataframe (df), with new data(N) to column name(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:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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