I have the below loop, I would like it to save all the dataframes into a csv as it loops but it only save the last loop. I am a newbee please advise where am I going wrong.
inverterdata=[]
for i in invertersinfo.items():
inverterdata.append([i[0],i[1]])
invdata=pd.DataFrame(inverterdata)
data = pd.json_normalize(json.loads(invdata.to_json(orient="records")))
hh=data.explode('1.telemetries')
data2 = pd.json_normalize(json.loads(hh.to_json(orient="records")))
data2 = data2.drop(['1.count', '0'], axis=1)
#data2.columns = data2.columns.str.replace(r'1.telemetries.', '')
data2.columns = [col.replace('1.telemetries.', '') for col in data2.columns]
data2.columns += "_"+ name
data2.to_csv("Samapledata.csv", index=False).