Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parse CSV in 2D Python Object

i am trying to do Analysis on a CSV file which looks like this:

timestamp value
1594512094.39 51
1594512094.74 76
1594512098.07 50.9
1594512099.59 76.80000305
1594512101.76 50.9

i am using pandas to import each column:

dataFrame = pandas.read_csv('iot_telemetry_data.csv')
graphDataHumidity: object = dataFrame.loc[:, "humidity"]
graphTime: object = dataFrame.loc[:, "ts"]

My Problem is i need to make a tuple of both columns, to filter the values of a specific time range, so for example i have my timestampBeginn of "1594512109.13668" and my "timestampEnd of "1594512129.37415" and i want to have the corresponding values to generate for example the mean value of the value of the specific time range.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I didn’t find any solutions to this online and i don’t know any libraries which solve this problem.

>Solution :

You can first filter the rows which timestamp values are between the ‘start’ and ‘end.’ Then you can calculate the values of the filtered rows, as follows:
(But, in the sample data, it seems that there is no row, which timestamp are between the range from 1594512109.13668 to 1594512129.37415. You can edit the range values as what you want.

import pandas as pd

df = pd.read_csv('iot_telemetry_data.csv')

start = 159451219.13668
end = 1594512129.37415

df = df[(df['timestamp'] >= start) & (df['timestamp'] <= end)]

average = df['value'].mean()
print(average)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading