interpolation

Pandas interpolation to extend data is giving bad results

Pandas interpolation to extend data is giving bad results Question: I have a dataset with ‘DEN’ values as a function of ‘Z’, which goes to Z = ~425000, but I would like to extend it up to Z = 500000. I attempted to do this by adding a new data point to my pandas column …

Total answers: 1

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 interpolate the first and the last values using pandas.DataFrame.interpolate?

How to interpolate the first and the last values using pandas.DataFrame.interpolate? Question: I know that this question has been asked before, but the suggested solutions that I found to not work for me. Maybe I am trying to do something that is simply not possible, but let me explain. I have a time-series data that …

Total answers: 1

Maintaining Sharp Corners in a Numpy Interpolation

Maintaining Sharp Corners in a Numpy Interpolation Question: I am interpolating a shape with numpy’s linspace and interp using gboffi‘s magnificent code from this post (included, below). This works well, however, the corners sometimes get missed and the resulting softened shape is undesired. I’d like to maintain the sharp corners of my shapes with an …

Total answers: 4

How to interpolate missing years within pd.groupby()

How to interpolate missing years within pd.groupby() Question: Problem: I have a dataframe that contains entries with 5 year time intervals. I need to group entries by ‘id’ columns and interpolate values between the first and last item in the group. I understand that it has to be some combination of groupby(), set_index() and interpolate() …

Total answers: 2

Pandas spline interpolation wrong?

Pandas spline interpolation wrong? Question: Pandas (Version 1.3.5) and SciPy (Version 1.7.3) give different result for spline interpolation and from my understanding pandas is wrong: df = pd.DataFrame(data = {‘values’: [10, 12, 15, None, None, None, None, 10, 5, 1, None, 0, 1, 3],}) df[‘interpolated_pandas’] = df[‘values’].interpolate(method=’spline’, axis=0, order=3) df[[‘interpolated_pandas’, ‘values’]].plot.line(); gives me: And idx …

Total answers: 2

xarray dataset extract values select

xarray dataset extract values select Question: I have a xarray dataset from which I would like to extract points based on their coordinates. When sel is used for two coordinates it returns a 2D array. Sometimes this is what I want and it is the intended behavior, but I would like to extract a line …

Total answers: 1

Interpolating column of first dataframe based on second dataframe

Interpolating column of first dataframe based on second dataframe Question: Suppose that I have 2 dataframes df1: col1 0 10 20 30 and df2: col1 val 0 0 5 2 15 4 25 5 33 8 I want to compute val column for df1 that is linearly interpolated from val in df2 based on col1. …

Total answers: 1

Pandas interpolate within a groupby for one column

Pandas interpolate within a groupby for one column Question: Similar to this question Pandas interpolate within a groupby but the answer to that question does the interpolate() for all columns. If I only want to limit the interpolate() to one column how do I do that? Input filename val1 val2 t 1 file1.csv 5 10 …

Total answers: 1