pandas-resample

resample('D').interpolate() fills value, but resample('Y').interpolate() produces nans?

resample('D').interpolate() fills value, but resample('Y').interpolate() produces nans? Question: Let’s start with two dates, two days apart, resample daily, and interpolate: In [1]: ts = pd.Series([1, 2], index=pd.DatetimeIndex([‘1950-01-01’, ‘1950-01-03’])) In [2]: ts.resample(‘D’).interpolate() Out[2]: 1950-01-01 1.0 1950-01-02 1.5 1950-01-03 2.0 Freq: D, dtype: float64 So far so good. Next, let’s try doing it with two dates two …

Total answers: 1

How to seperate dataframe in group with a five minutes interval?

How to seperate dataframe in group with a five minutes interval? Question: I have a dataframe like this: timestamp id data1 2022-12-12 10:03:02 a1 x1 2022-12-12 10:03:02 a2 c1 2022-12-12 10:04:12 a1 x2 2022-12-12 10:04:12 a2 c2 2022-12-12 10:05:02 a1 x3 2022-12-12 10:05:02 a2 c3 2022-12-12 10:09:15 a1 x4 2022-12-12 10:09:15 a2 c4 2022-12-12 10:12:15 …

Total answers: 1

frontfill or backfill of STRING column at resample() in pandas

frontfill or backfill of STRING column at resample() in pandas Question: is there any methode while doing resampling() to ffill() or bfill() a object column? Suppose we have: Date Sort Value 2022-10-23 15:40:41 A 1 2022-10-23 18:43:13 B 2 2022-10-24 15:40:41 C 3 2022-10-24 18:43:13 D 4 i would like to have following results with: …

Total answers: 2

Python: resample on a rolling basis

Python: resample on a rolling basis Question: I have a DataFrame as follows: data = [[99330,12,122], [1123,1230,1287], [123,101,812739], [1143,12301230,252], [234,342,4546], [2445,3453,3457], [7897,8657,5675], [46,5675,453], [76,484,3735], [363,93,4568], [385,568,367], [458,846,4847], [574,45747,658468], [57457,46534,4675]] df1 = pd.DataFrame(data, index=[‘2022-01-01’, ‘2022-01-02’, ‘2022-01-03’, ‘2022-01-04’, ‘2022-01-05’, ‘2022-01-06’, ‘2022-01-07’, ‘2022-01-08’, ‘2022-01-09’, ‘2022-01-10’, ‘2022-01-11’, ‘2022-01-12’, ‘2022-01-13’, ‘2022-01-14’], columns=[‘col_A’, ‘col_B’, ‘col_C’]) df1.index = pd.to_datetime(df1.index) df1.resample(‘1D’).last().rolling(7).last() The last …

Total answers: 1

How to prevent resample -> aggregate from dropping columns?

How to prevent resample -> aggregate from dropping columns? Question: Code df = pd.DataFrame( data = {‘A’: [1, 1, 2], ‘B’: [None, None, None]}, index = pd.DatetimeIndex([ ‘1990-01-01 00:00:00’, ‘1990-01-01 12:00:00’, ‘1990-01-02 12:00:00’ ]) ) print(df.resample(‘1d’).aggregate(‘mean’)) Output A 1990-01-01 1.0 1990-01-02 2.0 Desired output A B 1990-01-01 1.0 None 1990-01-02 2.0 None I don’t care …

Total answers: 2

Copying and appending rows to a dataframe with increment to timestamp column by a minute

Copying and appending rows to a dataframe with increment to timestamp column by a minute Question: Here is the dataframe I have: df = pd.DataFrame([[pd.Timestamp(2017, 1, 1, 12, 32, 0), 2, 3], [pd.Timestamp(2017, 1, 2, 12, 32, 0), 4, 9]], columns=[‘time’, ‘feature1’, ‘feature2’]) For every timestamp value found in the df (i.e for every value …

Total answers: 2