如何将 numpy 数组转换为天、小时、分钟?
How do I convert numpy array to days, hours, mins?
运行这个系列
X = number_of_logons_all.values
split = round(len(X) / 2)
X1, X2 = X[0:split], X[split:]
mean1, mean2 = X1.mean(), X2.mean()
var1, var2 = X1.var(), X2.var()
print('mean1=%f, mean2=%f' % (mean1, mean2))
print('variance1=%f, variance2=%f' % (var1, var2))
我得到:
mean1=60785.792548, mean2=61291.266868
variance1=7483553053.651829, variance2=7603208729.348722
但我希望在我的 PyCharm 控制台中有这样的东西(从另一个结果中提取):
>>> -103 days +04:37:13.802435724...
试图将 np.array 放在 pd.Dataframe() 中,通过添加
获得预期值
.apply(pd.to_timedelta, unit='s')
...这行不通,所以我尝试了
new = pd.DataFrame([mean1]).to_numpy(dtype='timedelta64[ns]')
...并且(仍然)得到了这样的东西:
>>>> [[63394]]
有人可以帮助我将上面的均值计算结果转换为易于理解的日期时间结果吗?
谢谢,感谢您的支持。
您可以使用 f-string
s:
mean1, mean2 = 60785.792548, 61291.266868
variance1, variance2=7603208729.348722,7483553053.651829
print(f'mean1={pd.Timedelta(mean1, unit="s")}, mean2={pd.Timedelta(mean2, unit="s")}')
print(f'variance1={pd.Timedelta(variance1, unit="s")}, variance2={pd.Timedelta(variance2, unit="s")}')
mean1=0 days 16:53:05.792548, mean2=0 days 17:01:31.266868
variance1=88000 days 02:25:29.348722458, variance2=86615 days 04:44:13.651828766
运行这个系列
X = number_of_logons_all.values
split = round(len(X) / 2)
X1, X2 = X[0:split], X[split:]
mean1, mean2 = X1.mean(), X2.mean()
var1, var2 = X1.var(), X2.var()
print('mean1=%f, mean2=%f' % (mean1, mean2))
print('variance1=%f, variance2=%f' % (var1, var2))
我得到:
mean1=60785.792548, mean2=61291.266868
variance1=7483553053.651829, variance2=7603208729.348722
但我希望在我的 PyCharm 控制台中有这样的东西(从另一个结果中提取):
>>> -103 days +04:37:13.802435724...
试图将 np.array 放在 pd.Dataframe() 中,通过添加
获得预期值.apply(pd.to_timedelta, unit='s')
...这行不通,所以我尝试了
new = pd.DataFrame([mean1]).to_numpy(dtype='timedelta64[ns]')
...并且(仍然)得到了这样的东西:
>>>> [[63394]]
有人可以帮助我将上面的均值计算结果转换为易于理解的日期时间结果吗?
谢谢,感谢您的支持。
您可以使用 f-string
s:
mean1, mean2 = 60785.792548, 61291.266868
variance1, variance2=7603208729.348722,7483553053.651829
print(f'mean1={pd.Timedelta(mean1, unit="s")}, mean2={pd.Timedelta(mean2, unit="s")}')
print(f'variance1={pd.Timedelta(variance1, unit="s")}, variance2={pd.Timedelta(variance2, unit="s")}')
mean1=0 days 16:53:05.792548, mean2=0 days 17:01:31.266868
variance1=88000 days 02:25:29.348722458, variance2=86615 days 04:44:13.651828766