You are asked to create a new column in a DataFrame that is the sum of two other columns. How would you create this new column in Pandas?

  • df.create_column('new_column', df.column1 + df.column2)
  • df.new_column = df.column1 + df.column2
  • df['new_column'] = df['column1'] + df['column2']
  • df['new_column'] = df['column1'].add(df['column2'])
To create a new column in a Pandas DataFrame that is the sum of two existing columns, you would use the syntax df['new_column'] = df['column1'] + df['column2']. This operation will perform element-wise addition and create the new column.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *