In a pandas DataFrame, foo for example:
>>> foo
col1 col2
0 1 0
1 2 0
2 3 1
If you want to add a new column, all with the same value you can do
>>> foo['col3'] = 1
>>> foo
col1 col2 col3
0 1 0 1
1 2 0 1
2 3 1 1
If you want to add another new column, all with specific values you can do
>>> foo['col4'] = ['a', 'b', 'c']
>>> foo
col1 col2 col3 col4
0 1 0 1 a
1 2 0 1 b
2 3 1 1 c
But what I want to do is add the same list to each row as new column. Something like
>>> myList = [True, False, False, True]
>>> foo['col5'] = {...something something something...}
>>> foo
col1 col2 col3 col4 col5
0 1 0 1 a [True, False, False, True]
1 2 0 1 b [True, False, False, True]
2 3 1 1 c [True, False, False, True]
Using the previous method results in ValueError('Length of values does not match length of ' 'index'). So at the moment, my {...something something something...} line is foo['col5'] = [myList] * foo.shape[0]. But I'm wondering, is there a better way?
foo['col5'] = [myList]*len(foo)