This is my current code
df['company_id'] = ''
length = 0
while length < len(df):
for x in df:
if df['associations.companies.results'][length] == 'nan':
df.loc[df['associations.companies.results'] == 'nan', 'company_id'] = 0
else:
df['company_id'][length] = df['associations.companies.results'][length][0]['id']
length = length +1
I tried to run this code with Lambda and np.where versions, however, these gave errors that I couldn't solve. The data set has close to 40 rows and I try to get the company ID out of a dict nested in a list. It looks like this on each row:
[{'id': 'XXXXXXXXXX', 'type': 'call_to_company'}]
sometimes there is no company_id and it will look like:
nan
The final result would be a separate column called "company_id" that contains the 'id' value.
Right now the code has been running for 30 mins and still going strong
Hope anyone can help. Thanks!