Python Forum
Write in a csv file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Write in a csv file (/thread-16628.html)



Write in a csv file - jeuvrey - Mar-07-2019

Hello,
I receive a data stream i want to record in a variable (array, list or dictionnary) and then write these data in a csv file.
My streamed data are coordinates of multiple marker. Hence at each loop i receive a data frame (marker1:x,y,z; marker 2:x,y,y ect..), so for exemple with 4 markers i receive 12 streamed data at each loop.
I would like to write these data in a csv file like this (data separated with tabulation):

marker 1.... marker 2....marker3 ect...
x y z......x y z......x y z
1 2 3......5 5 6......4 9 8
4 5 6......7 2 4......4 6 5

It seems simple but i really don't know what/how i can use array, list or dictionnary to do that.
Any help please?
Thanks


RE: Write in a csv file - Larz60+ - Mar-07-2019

you can do it directly in pandas, see:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html