Python Forum
Impute 1 if previous row of 'days' column is between 0 & 7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Impute 1 if previous row of 'days' column is between 0 & 7
#3
You can shift the days column.
import pandas as pd
df = pd.DataFrame({"Count":range(5)})
df[Shifted'] = df['Count'].shift(1)
print(df)
Output:
Count Shifted 0 0 NaN 1 1 0.0 2 2 1.0 3 3 2.0 4 4 3.0
Then you could use the shifted column in your function
Reply


Messages In This Thread
RE: Impute 1 if previous row of 'days' column is between 0 & 7 - by deanhystad - Dec-08-2022, 07:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How replace Unnamed header column with previous SriMekala 3 5,340 Aug-15-2019, 05:10 PM
Last Post: boring_accountant

Forum Jump:

User Panel Messages

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