Look at this code:
df=pd.DataFrame(data=[['a','b'],['c','d']],columns=['B','C'])
df.insert(loc=0,column='A',value='Hello world!')
What it does: It inserts a new column named 'A'
and writes 'Hello world!'
into each cell of that new columns. But now watch this:
df=pd.DataFrame(data=[['a','b'],['c','d']],columns=['B','C'])
df.insert(loc=0,column='A',value=['Hello','world!'])
Here we obtain a new column named 'A'
again, but this time we get 'Hello'
in the first cell and 'world!'
in the second. However, I want to have the list ['Hello','world!']
in both cells. How do I modify the call of the insert function to obtain what I want?