Python Forum
Interpolating DataFrame method=‘index’ help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interpolating DataFrame method=‘index’ help
#1
Given the following:
import pandas as pd
merged = pd.DataFrame({'Z':(0,1.,2.5,3.),'X':(-1.,None,None,0),'U':(0,1.,1.,0)})

for col in merged:
    merged[col] = pd.to_numeric(merged[col], errors='coerce')

print(pd.Series(data=merged['X'].values,index=merged['Z'].values)
    .interpolate(method='index'))
print('\nvs.\n',merged.interpolate(method='linear'))
Can I interpolate my data within the DataFrame similar to the 'linear' method but get the results achieved by indexing a series? I'm losing data by making the series and don't know how to get my answer otherwise.

Do I need to take my DataFrame, break it up into Series, then turn them back into a new interpolated DataFrame?
Reply
#2
You can set index, perform interpolation and drop the index:

merged.set_index('Z').interpolate(method='index').reset_index()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Getting Index Error - list index out of range krishna 2 2,566 Jan-09-2021, 08:29 AM
Last Post: buran
  Getting Index Error - list index out of range RahulSingh 2 6,101 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  How to find index of a particular value in a dataframe ankitawadhwa 0 2,363 Jan-21-2020, 09:45 PM
Last Post: ankitawadhwa
  How to add data to the categorical index of dataframe as data arrives? AlekseyPython 1 2,315 Oct-16-2019, 06:26 AM
Last Post: AlekseyPython
  Applying operation to a pandas multi index dataframe subgroup Nuovoq 1 2,618 Sep-04-2019, 10:04 PM
Last Post: Nuovoq
  How to get first and last row index of each unique names in pandas dataframe SriRajesh 1 4,451 Oct-13-2018, 07:04 AM
Last Post: perfringo
  DataFrame index issue Astrikor 2 2,999 Aug-25-2018, 04:25 PM
Last Post: Astrikor
  Newbie question to return only the index of a dataframe zydjohn 0 2,521 Jan-22-2018, 03:40 PM
Last Post: zydjohn
  is a pandas dataframe timeseries time index in a specified range (but ignoring date)? m_lotinga 4 19,080 Dec-12-2016, 10:51 PM
Last Post: m_lotinga

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020