I have a pandas dataframe. I have a column that could potentially have null values or an array of string values in it. But I'm having trouble working out how to store values in this column.
This is my code now:
df_completed = df[df.completed]
df['links'] = None
for i, row in df_completed.iterrows():
results = get_links(row['nct_id'])
if results:
df[df.nct_id == row['nct_id']].links = results
print df[df.nct_id == row['nct_id']].links
But this has two problems:
- When
results
is an array of length 1, the printed output is None, rather than the array, so I think I must be saving the value wrong - When
results
is a longer array, the line where I save the value produces an error:ValueError: Length of values does not match length of index
What am I doing wrong?