1

I'm bringing in data that is json.dumps'd to go through the MQTT broker. After I do a json.loads, I'm getting this data in return.

[['date here', '1713180'], ['date here', '1713181'], ['date here', '1713182'], ['date here', '1713183'], ['date here', '1713184']]

I've tried numerous other threads on csv writing, but I'm completely lost as to how to get this written properly to a CSV.

1

2 Answers 2

1

Simply:

import pandas as pd
df=pd.DataFrame([['date here', '1713180'], ['date here', '1713181'], ['date here', '1713182'], ['date here', '1713183'], ['date here', '1713184']])
df.columns=['timestamp','data']
df.to_csv('test.csv',columns=['timestamp','data'],index=False)
Sign up to request clarification or add additional context in comments.

Comments

1

"You can use pandas:

if you don't have pandas installed run the following in order to install it:

pip install pandas

then, you can use:

import pandas as pd

data = [['date here', '1713180'], ['date here', '1713181'], ['date here', '1713182'], ['date here', '1713183'], ['date here', '1713184']]
df = pd.DataFrame(data)

df.to_csv("path/to/file.csv")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.