how count average from exel using python

Question:

how count time average from excel using python row b or c

This my code

from datetime import datetime
import pandas as pd
import numpy as np
df = pd.read_excel('convert.xlsx')

t1 = pd.to_datetime(df['b'], format='%H:%M:%S')
t2 = pd.to_datetime(df['c'], format='%H:%M:%S')

delta = t2 - t1

print(delta)

enter image description here

enter image description here

Asked By: Ade Saputra

||

Answers:

You can use the .mean() function on the ‘delta’ variable to calculate the average time difference between the values in columns ‘b’ and ‘c’.

For example:

print(delta.mean())

This will output the average time difference between the values in columns ‘b’ and ‘c’ in the format ‘0 days 00:00:00.000000’

Alternatively, you can use the .mean() function on the ‘delta’ variable after converting it to seconds using the .total_seconds() method

For example:

print(delta.mean().total_seconds())

This will output the average time difference between the values in columns ‘b’ and ‘c’ in seconds.

Answered By: The Girl Programmer
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.