Home > Enterprise >  Parse CSV in 2D Python Object
Parse CSV in 2D Python Object

Time:01-21

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.

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

CodePudding user response:

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)
  •  Tags:  
  • Related