Screen Link: Learn data science with Python and R projects
def process_date(date): if "-" in date: splited_date = date.split("-") average_date = (int(splited_date) + int(splited_date)) / 2 final_date = round(average_date) else: final_date = int(date) return final_date
What Dataquest answer for code is:
def process_date(date): if "-" in date: split_date = date.split("-") date_one = split_date date_two = split_date date = (int(date_one) + int(date_two)) / 2 date = round(date) else: date = int(date) return date
I was creating the code for process_date function and my answer was different from Dataquest’s answer.
(Sorry Dataquest for not following your instruction! I just wanted to try )
I would like to know if my answer is still usable or not safe to use(meaning, it can cause error in the future or something).
Things I would like to confirm in my code are followings;
Is it ok to create calculation right after “date.split(”-")"?
⇨I wanted to make the coding short, so I cut defining part (Dq code: date_one = split_date&date_two = split_date)
Is it ok to assign different variable? (in dq they assign back to “date” at the end)
⇨I wanted to create new variable (we had "def process_date(date)"and at the end I assigned final data as “return final_date” instead of “return date”) so that we can differ before calculation variable and after calculation variable. Please let me know if that causes error in later on.
Sorry for asking so much details and silly question! Im still at the beginner level…
Thank you for your help in advance!