Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop saving only the last DataFrame in a csv file #148

Open
EricMoshani opened this issue Jul 19, 2023 · 1 comment
Open

Loop saving only the last DataFrame in a csv file #148

EricMoshani opened this issue Jul 19, 2023 · 1 comment

Comments

@EricMoshani
Copy link

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 = [col.replace('1.telemetries.', '') for col in data2.columns]
data2.columns += "_"+ name

data2.to_csv("Samapledata.csv", index=False).

@mkb79
Copy link
Owner

mkb79 commented Jul 19, 2023

What type of object invertersinfo is?

for i in invertersinfo.items():
   inverterdata.append([i[0],i[1]])

Which indention the following code have? The same indentation like the last line from above?

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 = [col.replace('1.telemetries.', '') for col in data2.columns]
data2.columns += "_"+ name

How is your question audible-cli related?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants