resampling

Resampling irregularly spaced data to a regular grid in Python

不想你离开。 提交于 2019-12-17 07:06:02
问题 I need to resample 2D-data to a regular grid. This is what my code looks like: import matplotlib.mlab as ml import numpy as np y = np.zeros((512,115)) x = np.zeros((512,115)) # Just random data for this test: data = np.random.randn(512,115) # filling the grid coordinates: for i in range(512): y[i,:]=np.arange(380,380+4*115,4) for i in range(115): x[:,i] = np.linspace(-8,8,512) y[:,i] -= np.linspace(-0.1,0.2,512) # Defining the regular grid y_i = np.arange(380,380+4*115,4) x_i = np.linspace(-8

Upsampling a time-series with different conditions for float64 vs object and int64 columns

早过忘川 提交于 2019-12-14 02:23:19
问题 I have a df similar to this: print(df) A B C DATE_TIME 2016-10-08 13:57:00 in 5.61 0 2016-10-08 14:02:00 in 8.05 0 2016-10-08 14:07:00 out 7.92 0 2016-10-08 14:12:00 in 7.98 1 2016-10-08 14:17:00 out 8.18 0 2016-10-08 14:22:00 out 7.59 0 print (df.dtypes) A object B float64 C int64 dtype: object I want to resample this df to a 1S frecuency, so that I can concatenate it with another df . The problem I can't solve is that for the columns type object and int64 I want the same value repeated for

Convert Pandas tseries object to a DataFrame

半腔热情 提交于 2019-12-13 16:05:01
问题 I wish to convert the following <'pandas.tseries.resample.DatetimeIndexResampler'> type object into a pandas DataFrame object ( <'pandas.core.frame.DataFrame'> ). However I cannot find the relevant function in the pandas documentation to allow me to do this. The data takes the following form: M30 Date 2016-02-29 -61.187699 2016-03-31 -60.869565 2016-04-30 -61.717922 2016-05-31 -61.823966 2016-06-30 -62.142100 ... Can anyone provide an alternative solution? 回答1: You need some aggregate

Pandas resample skip incomplete groups at the start

社会主义新天地 提交于 2019-12-13 04:23:05
问题 I have 15 min OHLC data coming in continuously from an API and I wish to resample it to 30 min 1H etc +----------------------+----------+----------+----------+----------+------------+ | time | open | high | low | close | volumeto | +----------------------+----------+----------+----------+----------+------------+ | | | | | | | | 2018-06-26 03:30:00 | 6244.56 | 6250.54 | 6243.55 | 6247.34 | 1801280.76 | | 2018-06-26 03:45:00 | 6247.34 | 6257.61 | 6246.43 | 6248.23 | 2551368.76 | | 2018-06-26 04

resamplig pandas (not as a timeseries)

倖福魔咒の 提交于 2019-12-13 03:46:08
问题 I have a pandas dataframe like this: index x y 0.010 1 Nan 0.011 Nan 3 0.014 NaN 4 0.019 9 Nan 0.020 10 7 This matrix comes from a concatenation of 2 matrices I would like to resample the index at equally spaced intervals, say 0.010, 0.012,0.014..... 0.020, filling the NaN with linear interpolation. Similar to what resample does if index were a time series... Can anyone send me hints? I am having an headache with this Thanks you 回答1: Solved! df1 = A.reindex(A.index.union(np.linspace(0.0,0.1

how to do mono to stereo conversion?

99封情书 提交于 2019-12-12 18:12:08
问题 I am using libswresample to resample from any PCM format to 44.1kHz, 16bit int, stereo. I was playing around with some audio volume analyzing of the resulting audio stream and I figured out that in case I have 44.1kHz, 16bit int mono as the source, I have roughly the formular: leftSample = sourceSample / sqrt(2); rightSample = sourceSample / sqrt(2); But I was expecting: leftSample = sourceSample; rightSample = sourceSample; (In case the source is stereo, I simply have leftSample =

How to resample / downsample an irregular timestamp list?

半城伤御伤魂 提交于 2019-12-12 16:22:37
问题 SImple question but I haven't been able to find a simple answer. I have a list of data which counts the time in seconds that events occur: [200.0 420.0 560.0 1100.0 1900.0 2700.0 3400.0 3900.0 4234.2 4800.0 etc..] I want to count how many events occur each hour (3600 seconds) and create a new list of these counts. I understand this is called downsampling, but all the information I can find is related to traditional time series. For the example above the new list would look like: [7 3 etc..]

Pandas - Calculating daily differences relative to earliest value

☆樱花仙子☆ 提交于 2019-12-12 13:15:54
问题 This is probably pretty easy, but for some reason I am finding it quite difficult to complete. Any tips would be greatly appreciated. I have some time series data consisting of 5-minute intervals each day, ala: Date Values 2012-12-05 09:30:00 5 2012-12-05 09:35:00 7 2012-12-05 09:40:00 3 2012-12-05 09:45:00 2 2012-12-05 09:50:00 15 2012-12-06 09:30:00 4 2012-12-06 09:35:00 3 2012-12-06 09:40:00 8 2012-12-06 09:45:00 1 I would like to calculate the differences relative to the first value of

Pandas Panel resampling alternatives

折月煮酒 提交于 2019-12-12 03:17:47
问题 I often use pd.Series.resample(), and am wondering if there is a way to resample/ interpolate monthly gridded data in the form (time,lat, lon) to say 'MS' (monthly start). I understand the feature is not directly implemented in Panel. Is there a workaround? 回答1: You should check out the xray package. It is an N-dimensional labeled array package that extends much of the pandas resampling/group-by functionality. It is a pure python package so is easy to install and includes some really nice

Round a Pandas Timestamp using an offset

妖精的绣舞 提交于 2019-12-11 18:17:32
问题 I would like to round (floor) a Pandas Timestamp using a pandas.tseries.offsets (like when resampling time series but with just one row) import pandas as pd from pandas.tseries.frequencies import to_offset freq = to_offset("H") dt = pd.Timestamp('2017-01-03 05:02:00') # what should I do # to get pd.Timestamp('2017-01-03 05:00:00') I wonder if pandas.core.resample.TimeGrouper can't help grouper = pd.Grouper(freq="H") 回答1: Timestamps may be rounded down using a time frequency string: https:/