This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# same iterrows() solution with change log | |
curr_year = 2020 | |
past_year = 2010 | |
change_log = [] | |
# loop through index and rows of df | |
for idx, row in df.iterrows(): | |
if row[col1].year > curr_year: | |
new_year = row[col2].year | |
# save reference data as tuple | |
records = tuple((row['case_id'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# iterate through a DataFrame with iterrows() | |
curr_year = 2020 | |
past_year = 2010 | |
# loop through index and rows of df | |
for idx, row in df.iterrows(): | |
# compare years as integers | |
if row[col1].year > curr_year: | |
# return received_date's year as integer | |
new_year = row[col2].year |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
col1 = 'event_date' | |
col_new = str(col1 + '_new') | |
col2 = 'received_date' | |
curr_year = 2020 | |
past_year = 2010 | |
# given a dataframe df with col1 and col2 as datetime columns |
NewerOlder