pandas-resample

What is the difference between bins when using groupby apply vs resample apply?

孤街浪徒 提交于 2021-02-11 15:37:54
问题 This is somewhat of a broad topic, but I will try to pare it to some specific questions. I have noticed a difference between resample and groupby that I am curious to learn about. Here is some hourly time series data: In[]: import pandas as pd dr = pd.date_range('01-01-2020 8:00', periods=10, freq='H') df = pd.DataFrame({'A':range(10), 'B':range(10,20), 'C':range(20,30)}, index=dr) df Out[]: A B C 2020-01-01 08:00:00 0 10 20 2020-01-01 09:00:00 1 11 21 2020-01-01 10:00:00 2 12 22 2020-01-01

What is the difference between bins when using groupby apply vs resample apply?

人走茶凉 提交于 2021-02-11 15:34:32
问题 This is somewhat of a broad topic, but I will try to pare it to some specific questions. I have noticed a difference between resample and groupby that I am curious to learn about. Here is some hourly time series data: In[]: import pandas as pd dr = pd.date_range('01-01-2020 8:00', periods=10, freq='H') df = pd.DataFrame({'A':range(10), 'B':range(10,20), 'C':range(20,30)}, index=dr) df Out[]: A B C 2020-01-01 08:00:00 0 10 20 2020-01-01 09:00:00 1 11 21 2020-01-01 10:00:00 2 12 22 2020-01-01

What is the difference between bins when using groupby apply vs resample apply?

浪尽此生 提交于 2021-02-11 15:34:28
问题 This is somewhat of a broad topic, but I will try to pare it to some specific questions. I have noticed a difference between resample and groupby that I am curious to learn about. Here is some hourly time series data: In[]: import pandas as pd dr = pd.date_range('01-01-2020 8:00', periods=10, freq='H') df = pd.DataFrame({'A':range(10), 'B':range(10,20), 'C':range(20,30)}, index=dr) df Out[]: A B C 2020-01-01 08:00:00 0 10 20 2020-01-01 09:00:00 1 11 21 2020-01-01 10:00:00 2 12 22 2020-01-01

Can I dynamically choose the method applied on a pandas Resampler object?

点点圈 提交于 2021-01-29 17:33:12
问题 I am trying to create a function which resamples time series data in pandas . I would like to have the option to specify the type of aggregation that occurs depending on what type of data I am sending through (i.e. for some data, taking the sum of each bin is appropriate, while for others, taking the mean is needed, etc.). For example data like these: import pandas as pd import numpy as np dr = pd.date_range('01-01-2020', '01-03-2020', freq='1H') df = pd.DataFrame(np.random.rand(len(dr)),

How can I fill gaps by mean in period datetime column in pandas dataframe?

夙愿已清 提交于 2021-01-05 07:07:41
问题 I have a dataframe like below: df = pd.DataFrame({'price': ['480,000,000','477,000,000', '608,700,000', '580,000,000', '350,000,000'], 'sale_date': ['1396/10/30','1396/10/30', '1396/11/01', '1396/11/03', '1396/11/07']}) df Out[7]: price sale_date 0 480,000,000 1396/10/30 1 477,000,000 1396/10/30 2 608,700,000 1396/11/01 3 580,000,000 1396/11/04 4 350,000,000 1396/11/04 So then i define period datetime and resample them by day df['sale_date']=df['sale_date'].str.replace('/','').astype(int) df[

Resampling boolean values in pandas

╄→尐↘猪︶ㄣ 提交于 2020-07-21 05:52:21
问题 I have run into a property which I find peculiar about resampling Booleans in pandas . Here is some time series data: import pandas as pd import numpy as np dr = pd.date_range('01-01-2020 5:00', periods=10, freq='H') df = pd.DataFrame({'Bools':[True,True,False,False,False,True,True,np.nan,np.nan,False], "Nums":range(10)}, index=dr) So the data look like: Bools Nums 2020-01-01 05:00:00 True 0 2020-01-01 06:00:00 True 1 2020-01-01 07:00:00 False 2 2020-01-01 08:00:00 False 3 2020-01-01 09:00:00

Resampling boolean values in pandas

孤街浪徒 提交于 2020-07-21 05:52:08
问题 I have run into a property which I find peculiar about resampling Booleans in pandas . Here is some time series data: import pandas as pd import numpy as np dr = pd.date_range('01-01-2020 5:00', periods=10, freq='H') df = pd.DataFrame({'Bools':[True,True,False,False,False,True,True,np.nan,np.nan,False], "Nums":range(10)}, index=dr) So the data look like: Bools Nums 2020-01-01 05:00:00 True 0 2020-01-01 06:00:00 True 1 2020-01-01 07:00:00 False 2 2020-01-01 08:00:00 False 3 2020-01-01 09:00:00