这可能看起来像是一个迂腐的问题,但这不是它的精神。考虑下面的代码:
import pandas as pd
period=pd.Period("2020-03-15","M") #This object ignores the specific day
print(period.asfreq("D")) #converts to last of month
print(period.to_timestamp()) #converts to first of month
字符串
这打印了2020-03-31,然后打印了2017-03-01 00:00:00.为什么会有不同的行为?我问这个问题的原因是因为Pandas似乎会因为特定的原因而做出特定的选择,所以可能这个原因对Pandas中的时间戳和周期之间的差异有一些具体或概念上的理解。
1条答案
按热度按时间9ceoxa921#
在
Period.to_timestamp
中使用参数how
表示月份的最后一天:字符串
如果需要删除次数,则表示设置为
00:00:00
使用Timestamp.normalize
:型
差异的原因是
Period.asfreq
和Period.to_timestamp
中的默认参数不同:的字符串