英文:
parsing a 360-day calendar in pandas
问题
我需要读取一个包含360天日历格式日期的csv文件,每个月有30天!是否有办法告诉pandas可以有30天的二月?它总是抛出"月份超出范围"的错误!
我尝试了普通的to_datetime函数,但没有成功。
编辑:我必须处理几种不同的日历类型,所以最好允许pandas做出异常,而不仅仅指定360天日历为唯一类型。
提前谢谢!
英文:
I need to read in a csv file that contains dates in the 360-day calendar format, each month having 30 days! Is there a way to tell pandas that it is okay to have a 30 day february? It always throws "day out of range for month" error!
I tried normal to_datetime function which didn't work.
Edit: I have to handle a few different calendar types, so it would be ideal to just allow pandas to make exceptions, and not just specify somehow the 360-day calendar as the only type.
Thank you in advance!
答案1
得分: 1
这是翻译后的内容:
这是翻译后的内容:
它几乎是不可能的,因为Python的pandas库期望日期采用“标准的格里高利历”格式,即每个月都有特定的天数。
我认为它没有内置选项来处理30天的二月。
但是pandas库中有一个函数 - pd.DateOffset(days=30)
。您可以探索这个选项。
英文:
Its quite not possible, as the python pandas expects dates to be in the standard Gregorian calendar
format, that is each month having a specific number of days.
I don't think it has a built in option to handle a 30 day February.
But there is a function in pandas
- pd.DateOffset(days=30)
. You can explore this.
答案2
得分: 0
不,这在标准日期时间格式中是不可能的。仅因为二月没有30天。
看一下这个,看起来类似。
英文:
No, this is not possible with the standard datetime format. Simply because there are no 30 days in february.
Take a look at this, looks similar.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论