Suppose now I have a dataframe with nested attributes. first dataframe
|species|quantity|date|
| --------|-------|------|
| ['apple', 'banana', 'carrots']| 20|0921
| ['apple', 'banana']| 10|0922
| ['apple']| 5|0923
Is there a possible way to faster iterate the dataframe to a normal dataframe? such that: dataframe i need
|species |quantity |date|
| -------- | ------- |------|
|apple| 20|0921
| banana| 20|0921
| carrots| 20|0921
| apple| 10|0922
| banana| 10|0922
I tried to use a method to iterate whole datasets repeatedly, but it seems too slow. any better ideas?
for i in species:
for index, row in df.iterrows():
if i in row['species']:
new_df = new_df.append({'species':i,'quantity':row['quantity'],'date':row['date']}, ignore_index=True)
I don't want to use explode, as it will create many null values