I have a data frame in which there are about 20 columns. One of the columns is called "source_name" and has values such as "John Doe" or "Jane Doe." I want to split it into 2 columns: "First_Name" and "Last_Name". When I run the following, it works as expected and splits the row into 2 columns:
data[['First_Name', 'Last_Name']] = data.director_name.str.split(' ', expand
= True)
data
First_Name Last_Name
John Doe
It works fine, however it does NOT work when I have NULL (NaN) values under the name "director_name". It produces the following error:
'Columns must be same length as key'
I would like to add a function that checks if! = Null, and then execute the above command, otherwise enter "NA" for First_Name and "Last_Name"
Any ideas how I will do this?
EDIT:
, , NULL. 3-4 . .
John Allen Doe
John Allen Doe Jr
, First_Name Last_Name.