Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add fill_value option to resample() #3715

Closed
gerdemb opened this issue May 30, 2013 · 3 comments
Closed

ENH: Add fill_value option to resample() #3715

gerdemb opened this issue May 30, 2013 · 3 comments
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Resample resample method
Milestone

Comments

@gerdemb
Copy link

gerdemb commented May 30, 2013

see also #3707

Add a fill_value option to resample() so that it is possible to resample a TimeSeries without creating NaN values. If the series is an int dtype and an int is passed to fill_value, it should be possible to resample the series without casting the values to floats.

>>> dates = (datetime(2013, 1, 1), datetime(2013,1,2), datetime(2013,3,1))
>>> s = Series([1,2,4],index=dates)
>>> s
2013-01-01    1
2013-01-02    2
2013-03-01    4
dtype: int64
>>> s.resample('M', how='sum')
2013-01-31     3
2013-02-28   NaN
2013-03-31     4
Freq: M, dtype: float64
>>> s.resample('M', how='sum', fill_value=0)
2013-01-31     3
2013-02-28     0
2013-03-31     4
Freq: M, dtype: int64
@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 11, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@nchmura4
Copy link
Contributor

wouldn't this be the right way to do this?
s.resample('M').sum().fillna(0)

@jreback
Copy link
Contributor

jreback commented Oct 31, 2016

@nchmura4 that is a way, but this issue is about filling before reindexing, like .reindex provides.

e.g. compare this

In [9]: s.reindex(pd.date_range(s.index.min(), s.index.max(), freq='D'), fill_value=0).resample('M').sum()
Out[9]:
2013-01-31    3
2013-02-28    0
2013-03-31    4
Freq: M, dtype: int64

In [10]: s.reindex(pd.date_range(s.index.min(), s.index.max(), freq='D'), fill_value=1).resample('M').sum()
Out[10]:
2013-01-31    32
2013-02-28    28
2013-03-31     4
Freq: M, dtype: int64

@nchmura4
Copy link
Contributor

got it. thanks for the clarification!

nchmura4 added a commit to nchmura4/pandas that referenced this issue Nov 25, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Nov 29, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Nov 30, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 2, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 2, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 2, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 2, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 2, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 3, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 21, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 21, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 21, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 21, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 21, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 31, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 31, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 31, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 31, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Dec 31, 2016
nchmura4 added a commit to nchmura4/pandas that referenced this issue Jan 18, 2017
nchmura4 added a commit to nchmura4/pandas that referenced this issue Jan 18, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Jan 21, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants