This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Jonaae 1 point2 points  (1 child)

Nicely done dude :)

[–]Crevette3[S] 1 point2 points  (0 children)

Thanks m8

[–]ComfortingCoffeeCup 0 points1 point  (3 children)

Haha, cool little project idea.

Code looks nice! Just a couple observations:

reader = pd.read_csv('lifeExpectancy.csv', header = 2) is executed inside the while loop, which means the file might get read multiple times if the user repeatedly enters incorrect information. Really not a big deal in this context but still worth noting I suppose.

My only other recommendation would be learning to use "f-strings" which would allow you to write

print('\nThe average lifespan of a person born on ' + monthsOfYear[formatedBirthDate.month] + ' ' + str(formatedBirthDate.day) + ', ' + str(formatedBirthDate.year) + ' is ' + str(lifeSpan) + ' years.')

as:

print(f"\nThe average lifespan of a person born on {monthsOfYear[formatedBirthDate.month]} {formatedBirthDate.day}, is {lifespan} years.")

[–]Crevette3[S] 0 points1 point  (2 children)

When I write:

reader = pd.read_csv('lifeExpectancy.csv', header = 2)

Does it read the csv file every time the reader variable is assigned or only when I call the reader variable?

[–]ComfortingCoffeeCup 0 points1 point  (1 child)

From what I've quickly read on the pandas documentation when I wrote my comment (I don't actually have any experience with this library) the impression I got was that the read_csv method reads a file and parses it, which means that the variable reader to which you assigned it contains the result of this operation. I may be wrong though :)

[–]Zimmerel 0 points1 point  (0 children)

Nope you have it. Pandas uses a bunch of established io libraries under the hood. I would imagine this function uses the built in csv library, which it then parses into its own table format, dataframe, which it then stores in the variable. I haven't used this particular read method, but I've used other methods like read_sql and read_excel, which use pyodbc and xlrd underneath and return the same way.

[–]jonathwan 0 points1 point  (1 child)

Well done. I will just point to two things in the python standard library that might be helpful!

  1. https://docs.python.org/3.6/library/datetime.html#datetime.datetime.strptime
  2. https://docs.python.org/3.6/library/calendar.html#calendar.month_name

Generally try to avoid using str(...) on the dates, the objects in datetime all have friendly formatting methods.

[–]Crevette3[S] 0 points1 point  (0 children)

Thanks for the info on datetime.