'Adding new column in Pandas

Is there a way to insert a new column in Pandas where its name comes from a variable?

Help very much appreciated.

Many thanks



Solution 1:[1]

You can try the below:

varA = 'sometext'
df[varA] = 'testValue'

This will add column sometext with data testValue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vaibhav Jadhav