简体   繁体   English

在python中完成(及时进行数据分析)

[英]Terciles in python (Data analysis in time)

Regards, I have drawbacks in generating the following report, I have two fields of time one initial and one final; 在生成以下报告方面,我有缺点,我有两个时间字段,一个是初始时间,一个是最后时间; What is desired is to divide the time into three equal parts (start, intermediate and final). 期望将时间分成三个相等的部分(开始,中间和最后)。

I was trying to do it with numpy but I do not have enough documentation. 我试图用numpy来做,但是我没有足够的文档。

Some help. 一些帮助。

Thank you. 谢谢。

To divide two endpoints into equal segments, use linspace : 要将两个端点划分为相等的段,请使用linspace

import numpy as np

np.linspace(100, 250, 3)

Yields: 产量:

array([ 100.,  175.,  250.])

In general, for N segments you'd need one point for each segment, plus an end cap, for N+1 total points: 通常,对于N个细分受众群,您需要为每个细分受众群分配一个点,以及一个上限(总共N + 1个点):

np.linspace(start, stop, N+1)

Thanks for your suggestion, I found a combination with numpy and pandas libraries; 感谢您的建议,我找到了numpy和pandas库的组合; With your suggestion only probe with numpy and I threw an error for being fields of type datetime and this I could solve with pandas: 根据您的建议,仅使用numpy进行探测,而我将其作为datetime类型的字段抛出了一个错误,而我可以用pandas解决:

import pandas as pd
import numpy as np

start = pd.Timestamp(start_field)
fin = pd.Timestamp(final_field)
np.linspace(start.value, fin.value, 4) # 4 is the number of divisions.

thanks, again. 再次感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM