Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to initialize multiple columns to existing pandas DataFrame

how can I initialize multiple columns in a single instance in an existing pandas DataFrame object? I can initialize single column at an instance, this way:

df = pd.DataFrame({'a':[1,2,3],'b':[4,5,6]}, dtype='int')
df['c'] = 0

but i cannot do something like:

df[['c','d']] = 0 or
df[['c']['d']] = 0

is there a way i can achieve this?

like image 470
Siraj S. Avatar asked Sep 28 '16 21:09

Siraj S.


1 Answers

I prefer this solution.

    df = df.assign(**{'c': 0, 'd': 0})
like image 184
fleurette Avatar answered Sep 18 '22 12:09

fleurette