- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我尝试获取各种 pandas 日期的日期增量。但是,对于 >292 年的时间增量,我得到负值。例如,
import pandas as pd
dates = pd.Series(pd.date_range('1700-01-01', periods=4500, freq='m'))
days_delta = (dates-dates.min()).astype('timedelta64[D]')
但是,使用 DatetimeIndex 我可以做到并且它按我想要的方式工作,
import pandas as pd
import numpy as np
dates = pd.date_range('1700-01-01', periods=4500, freq='m')
days_fun = np.vectorize(lambda x: x.days)
days_delta = days_fun(dates.date - dates.date.min())
接下来的问题是如何为 Series 对象获取正确的 days_delta?
最佳答案
阅读here特别是关于 timedelta 限制:
Pandas represents Timedeltas in nanosecond resolution using 64 bit integers. As such, the 64 bit integer limits determine the Timedelta limits.
顺便说一句,这与文档中提到的 Pandas 时间戳中的限制相同:
Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years
这表明文档为规避时间戳限制而提出的相同建议可以应用于时间增量。时间戳限制的解决方案可在文档 ( here ) 中找到:
If you have data that is outside of the Timestamp bounds, see Timestamp limitations, then you can use a PeriodIndex and/or Series of Periods to do computations.
关于python - 相隔 >292 年的日期差值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35814172/
我的 C 代码有问题。我所做的就是这样: #include int main() { float zahlen[2]; for (int i = 0; i < 2; i++) {
我是一名优秀的程序员,十分优秀!