Sample Data:
import pandas as pd
df1=pd.DataFrame({'Original City': {'Daimler': 'Chicago',
'Mitsubishi': 'LA',
'Tesla': 'Vienna',
'Toyota': 'Zurich',
'Renault': 'Sydney',
'Ford': 'Toronto'}})
df2=pd.DataFrame({'Current City': {'Tesla': 'Amsterdam',
'Renault': 'Paris',
'BMW': 'Munich',
'Fiat': 'Detroit',
'Audi': 'Berlin',
'Ferrari': 'Bruxelles'}})
Now my question is:
I am trying to create a column containing whitespace using assign() method:
df1.assign(Original City=df2['Current City'])
^
#white space
I tried:
df1.assign('Original City'=df2['Current City'])
df1.assign(r'Original City'=df2['Current City'])
And as expected It is giving me an error:
File "<ipython-input-132-2ac564ac9d47>", line 1
df1.assign(Original City=df2['Current City'])
^
SyntaxError: invalid syntax
But I can able to assign my column like this:
df1.assign(OriginalCity=df2['Current City'])
Is it possible to create a column containing ' ' space(white space) using assign() method?
dict(a=1)works butdict(a b=1)doesnot