Currently im trying to code a program for predictive analytics, but i am having some problems figuring out how to print out the daily median on a dataframe I'm having problems with trying to figure out the daily median of the 'up-time' on a dataframe.
My code looks like this:
import glob
import os
import pandas as pd
import numpy as np
import time
import matplotlib.pyplot as plt
path = r'C:\Users\eneki\OneDrive\001. HHS\.LVNL\Documentatie\MNT-COM\testdata'
filenames = glob.glob(os.path.join(path + '/*.csv'))
li= []
for filename in filenames:
df = pd.read_csv(filename, index_col=None, header= 0)
li.append(df)
def daily_mean(df, date, col):
return df[date][col].mean()
data=np.random.rand(10)
columns = Data['up-time']
times= pd.date_range('14/10/2021', freq='1D', periods = 10)
Data = pd.DataFrame(data=data, index=times, columns=columns)
dates= df.index.strftime('%d%m%Y').unique()
means=df.groupby(pd.Grouper(freq='1D')).mean()
This is what my dataframe looks like:
In [152]: Data.iloc[:, : 8]
Out[152]:
Date Time ... OS Version up-time
0 14/10/2021 00:05:18 ... 7.0.2 17867351 U2 2900565
1 14/10/2021 00:10:19 ... 7.0.2 17867351 U2 2893095
2 14/10/2021 00:20:21 ... 7.0.2 17867351 U2 2901468
3 14/10/2021 00:25:19 ... 7.0.2 17867351 U2 2893995
4 14/10/2021 00:35:18 ... 7.0.2 17867351 U2 2902365
... ... ... ... ...
2414 26/10/2021 11:10:18 ... 7.0.2 17867351 U2 182031
2415 26/10/2021 11:20:17 ... 7.0.2 17867351 U2 182631
2416 26/10/2021 11:25:18 ... 7.0.2 17867351 U2 182931
2417 26/10/2021 11:35:20 ... 7.0.2 17867351 U2 183534
2418 26/10/2021 11:40:20 ... 7.0.2 17867351 U2 183833
[2419 rows x 8 columns]
And the error i get is:
ValueError: Shape of passed values is (10, 1), indices imply (10, 2419)
When i apply the exact numbers i get another error:
AttributeError: 'RangeIndex' object has no attribute 'strftime'
Is it because of a standard format in the date/time, Anyways, I dont really know how to fix it. Anyone familiar with this problem ?