Informatics Practices

How would you add a new column namely 'val' to a dataframe df that has 10 rows in it and has columns as 'Item', 'Qty', 'Price' ? You can choose to put any values of your choice.

Python Pandas

4 Likes

Answer

The syntax to add a new column to a DataFrame is <DF object>.[<column>] = <new value>. Therefore, according to this syntax, the statement to add a column named 'val' to a dataframe df with 10 rows is :

df['val'] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Answered By

3 Likes


Related Questions