-1

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.

The Oracle
  • 388
  • 1
  • 9
  • 23
  • Please provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) & [provide a reproducible copy of the DataFrame with `to_clipboard`](https://stackoverflow.com/questions/52413246/provide-a-reproducible-copy-of-the-dataframe-with-to-clipboard/52413247#52413247) – Trenton McKinney Oct 29 '19 at 22:29
  • Does this answer your question? [Add one row to pandas DataFrame](https://stackoverflow.com/questions/10715965/add-one-row-to-pandas-dataframe) – Trenton McKinney Oct 29 '19 at 22:31
  • Hi- unfortunately it doesnt. I just want to append to a column titled "Name". – The Oracle Oct 29 '19 at 22:59
  • Add just a new column with new values respect the for??? – GiovaniSalazar Oct 29 '19 at 23:29

1 Answers1

-1

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]

libin
  • 420
  • 3
  • 7