Lost1
Lost1

Reputation: 1062

pandas interpolations does not work for date index

I mocked the following data in a file:

Date,price
20010101,1
20010102,
20010104,4

Then to load this, I used

df = pd.read_csv("file_path", parse_dates=["Date"])

Neither the commands

df.interpolate("value")
df.interpolate("time")

worked. I expect the output to be

          price
Date     
20010101    1
20010102    2
20010104    4

ps. I forgot to say I did:

df.set_index("Date")

Upvotes: 1

Views: 70

Answers (1)

user2285236
user2285236

Reputation:

In order to use the time method you need to set the date column as index.

df.set_index('Date').interpolate(method='time')
Out: 
            price
Date             
2001-01-01    1.0
2001-01-02    2.0
2001-01-04    4.0

Upvotes: 2

Related Questions