23 Aug 2023

Posted on:

29 Jul 2023

0

# Resolved:Practice Exam 1- Q3- Can you please provide formula to exact dates before subtracting??

How to use code to extract those exact loan ids' dates from the table above, as dates, and then do calculations based on those? If possible/needed to store them in variables too. Thanks for your time.

Posted on:

29 Jul 2023

0

I tried some ineffective code solution but gave back error:

date1info = str( pd.read_csv('Lending-company-mod-exam.csv', index_col = 'LoanID', skiprows = 6))

Posted on:

29 Jul 2023

0

I noticed i highlighted by mistake row 1 and 3 cell, while its 1 and 4 in the exercise. Sorry for the mistake. But logic remains the same in  the solution.

Instructor
Posted on:

31 Jul 2023

1

Hi Panagiotis!

Thanks for reaching out!

Could please you clarify your exact intention? Are you aiming to construct a new DataFrame that only includes rows associated with the two specific dates you mentioned?

Best,

Ivan

Posted on:

04 Aug 2023

0

Yes sir. Thanks for the rephrasing.

Instructor
Posted on:

08 Aug 2023

1

Hi Panagiotis!

You can use the .iloc() method to extract the specified rows with converted dates.

`selected_rows = df.iloc[[1,4], :] `

Hope this helps.

Best,

Ivan

Posted on:

09 Aug 2023

0

Thanks teacher. To be precise what worked for us here was turn the row into the proper format:

df = pd.DataFrame(data)

df['StartDate'] = pd.to_datetime(df['StartDate'], format="%d/%m/%Y")

Then select the specific rows:

selected_rows = df.iloc[[0, 3], 5] which will pick the 6th value (the dates), from rows 1 and 4.

and finally store the values in two variables and calculate their difference:

date_1=  selected_rows[1]

print(date_1)

date_2 = selected_rows[4]

print(date_2)

and:

dif_days = date_1 - date_2

print(dif_days)

which gives us the 633 days.

Posted on:

09 Aug 2023

0

Only reason i wanted to try this verbose overcomplicated solution was not to trouble with your and my precious time, but experiment with if it was possible for the user to not explicitely type the dates himself, but rather cold extract them from the table to avoid mistakes. i hope the scope of this exploration makes a bit sense.

Instructor
Posted on:

23 Aug 2023

1

Hi Panagiotis!

Thanks for sharing this information with the Community!

Exploring various methods and well-reasoned suggestions is always beneficial, provided they function as intended. I appreciate your meticulousness in seeking improved alternatives and strategies. Thank you.

Best,

Ivan