Finding statistics, such as the mean, of all entries in a CSV file using Python

Viewed 92

I have a CSV file with 160 rows and 245 columns. It represents different pixels on a screen and each one takes a value. I want to calculate the mean over all the pixels/entries but can only find documentation on each row or column. How can I find the mean of the entire file?

1 Answers

You juste have to load your dataframe with pandas, transform it into a numpy.array and then call np.array.mean().

example

df = pd.read_csv('your_dataframe.csv', sep=';', decimal=',').to_numpy()
mean = df.mean()
Related