-1

I write here because I am working on a Python project that logs the voltage values of a sensor connected to a Raspberry Pi through an ADC converter and write them in a csv file. This part is working just fine, however after the logging (which is triggered by a button in the GUIzero UI) is finished, I would like to be able to draw a graph of these values, triggered the same way.

This is why I would like to read all the data from the csv and store them into a table, which I can them define as the values from my y-axis, before I draw the graph with matplotlib. However, I couldn't find a proper way to do so, I tried to put these values into a table, but when I try to print it (just to check it is working well), nothing appears and my csv file is empty after that, which I don't want...

I am quite a newbie in programming/Raspberry Pi stuff so any help would be very appreciated ! Thanks in advance !

1 Answer 1

1

Would pandas perhaps help? I'm not 100% sure what you're doing but you can save the contents of a csv file into a data frame like this:

import pandas as pd

df = pd.read_csv("file.csv",sep=',')

You can change the sep to whichever delimiter is separating your data. If your data has headers you can use:

df = pd.read_csv("file.csv",sep=',', header = 0)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, I have found some sort of a solution; but it is still missing a little something to work perfectly. I managed to read all the values from the file and store them into a list, but for this I had to create the list first, with an interation of the number measured (1500, with the first value of the list equal to 1 and the last to 1500). Then in the loop reading the value, I replace the value of the table with the measurement. This is ok for me, however the values I read are into brackets and they are kind of not recognised by matplotlib when I ask him to draw the graph
I get the following error : ValueError : setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (1501, ) + inhomogeneous part
Hey! Sorry, was out yesterday. Could you add a snippet of the csv file you're trying to import? Or a mock version if the contents are confidential.

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.