python - 将 pandas._libs.tslibs.offsets.QuarterEnd 转换为整数
python - convert pandas._libs.tslibs.offsets.QuarterEnd to integer
我有两个约会对象:
a = (pd.to_datetime(20191231, format='%Y%m%d') + pd.offsets.MonthEnd(n=0)).to_period('Q')
b = (pd.Timestamp(str(2020) + '-' + str(4 * 3)) + pd.offsets.MonthEnd(n=0)).to_period('Q')
我算了他们的差:
c = a - b
c
的类型仍然是pandas._libs.tslibs.offsets.QuarterEnd
。有没有办法可以将 c
转换为整数(四分之一差数)?
我们可以使用 QuarterEnd
中的 n
属性来获得预期的结果:
>>> c = a - b
>>> c.n
-4
我有两个约会对象:
a = (pd.to_datetime(20191231, format='%Y%m%d') + pd.offsets.MonthEnd(n=0)).to_period('Q')
b = (pd.Timestamp(str(2020) + '-' + str(4 * 3)) + pd.offsets.MonthEnd(n=0)).to_period('Q')
我算了他们的差:
c = a - b
c
的类型仍然是pandas._libs.tslibs.offsets.QuarterEnd
。有没有办法可以将 c
转换为整数(四分之一差数)?
我们可以使用 QuarterEnd
中的 n
属性来获得预期的结果:
>>> c = a - b
>>> c.n
-4