I have a huge dataframe (9530232x19) of twitter data. The first column includes a dictionary. I want to make seperate columns from that dictionary items in the same df. Also I have a dictionary in 'entities' column which I want to make a similar seperation.
I want to add the metrics as four new columns such as 'rtcount', 'reply_count', 'like_count', and 'quote_count', and entities['htype'] as a new column on the right of my existing df, without creating any more dataframes because this big df uses almost all of my 16 GB RAM and crashes occasionally. I know using a for loop for this big df is not an efficient way but I couldn't figure out how to do it otherwise.
Any help is very much appreciated.
htypedf=[]
t=[]
for i in range(0,len(d)):
if i%100==0:
print(i)
htype=[]
hasht=[]
t=d[i:i+1]
metrics=pd.Series(t['public_metrics'][0]).to_frame().T
try:
htype=list(map(lambda x : x['type'], t['entities'][0]['annotations']))
except:
htype=('NaN')
d.iloc[i] = pd.concat([t, metrics, pd.DataFrame({'htype': [htype]})],axis=1)