本文介绍了AttributeError:"TimedeltaProperties"对象在 pandas 中没有属性"years"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在熊猫中,为什么 TimedeltaProperties 对象没有属性'years'?

In Pandas, why does a TimedeltaProperties object have no attribute 'years'?

毕竟, datetime 对象具有此属性.

After all, the datetime object has this property.

对于一个与时间有关的物体来说,这似乎是很自然的事情.尤其是如果它已经具有小时,秒等属性.

It seems like a very natural thing for an object that is concerned with time to have. Especially if it already has an hours, seconds, etc attribute.

是否有一种解决方法,以便我的列充满了像
这样的值 10060天
可以转换成年?还是更好,只是将其转换为整数表示形式多年?

Is there a workaround so that my column, which is full of values like
10060 days,
can be converted to years? Or better yet, just converted to an integer representation for years?

推荐答案

TimedeltaProperties 不具有 year month 属性,因为根据TimedeltaProperties源代码.是-

TimedeltaProperties does not have year or month attributes because according to TimedeltaProperties source code . It is -

但是, months years 没有常量定义.

But , months or years have no constant definition.

1个月可以花费不同的天数,例如1月-> 31天,4月-> 30天等.

1 month can take on different different number of days, based on the month itself, like January -> 31 days , April -> 30 days , etc.

1个月也可以根据年份采用不同的值(如果是2月,则为年份),如果年份为2004年,则2月为29天,如果年份为2003年,则2月为28天.天,等等.

1 month can take on different values based on the year as well (in case of February month) , if the year is 2004 , February has 29 days , if the year is 2003 February has 28 days, etc.

years 的情况与此相同,它可以根据确切的年份采用不同的值,例如-如果年份为2003,则为365天,如果年份为2004,则为它有366天.

Same is the case with years , it can take on different values based on which exact year it is, for example - if the year is 2003 , it has 365 days, if the year is 2004 it has 366 days.

因此,诸如-将 10060天转换为 years 的要求是不准确的,哪个 years ?

Hence, an requirement like - Convert 10060 days to years is not accurate, which years?

像以前所说的,准确的年数没有.的天数取决于这些天代表的实际年份.

Like previously stated, the accurate amount of years those no. of days correspond to depend on the actual years those days represent.

这篇关于AttributeError:"TimedeltaProperties"对象在 pandas 中没有属性"years"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 14:18