开发者

Python Resample: How do I keep NaN as NaN?

When resample from monthly data to quarterly, I want my last value NaN to remain as NaN. How should I tweak my code?

Thank you

Python Resample: How do I keep NaN as NaN?

df=pd.read_excel(input_file, sheet_name='Sheet1', usecols='A:D', na_values='ND', index_col=0, header=0)
df.index.names = ['Period']
df.index = pd.to_datetime(df.index)


q0= pd.Series(df['HS6P1'], index=df.index)

m1 = q0.resample('Q'开发者_JAVA百科).sum()

Current Output

Period

1989-03-31 212.7

1989-06-30 302.1

1989-09-30 272.1

1989-12-31 163.9

Desired Output

Period

1989-03-31 212.7

1989-06-30 302.1

1989-09-30 272.1

1989-12-31 NaN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜