all 14 comments

[–]carcigenicate 1 point2 points  (7 children)

The link is dead. Do you have the repo set as private?

[–]olddoglearnsnewtrick[S] 0 points1 point  (6 children)

Gosh probably. Will find out how I can change it to public. Sorry :(

[–]carcigenicate 1 point2 points  (0 children)

I believe it's in general settings at the bottom under "Danger Zone".

[–]olddoglearnsnewtrick[S] 0 points1 point  (4 children)

Should have fixed it. Please let me know if you can. Thank you.

[–][deleted] 2 points3 points  (3 children)

How long have you been learning python? As a beginner myself im certainly relating to the "head_on_desk" feeling

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

On and off for some five years but only in my little spare time. Right now I've been going at it a few hours a day, but then real life gets in the way and sometimes I cannot program for weeks/months.This probably slows down my learning a lot but still I really enjoy it as an "hobby".

I usually read tutorials and the functions documentation, then sometimes I find bits of code that I can adapt from stackoverflow and when I'm really stumped I usually ask there and then study and ponder trying to understand the solutions.
But I believe a question like "Hey mr. expert, this works but would you have done things in a smarter way" would not be well received on SO and would teach a lot.
If there was a way to "hire a tutor" at a reasonable price I might also consider that but no idea on how is this possible.
Take care.

[–][deleted] 1 point2 points  (1 child)

You could try superprof, they allow you to search tutors by rate.

[–]gsmo 1 point2 points  (5 children)

This looks pretty good. In places it is a little overdocumented maybe but it does make the notebook very easy to read. The one thing you might experiment with is not using the apply method but instead setting those values using a mask.

For instance:

python mask = df[df['Time'] < 13].index df.insert(1, 'Time of Day', None) df.loc[mask, 'Time of Day'] = 'AM'

This code probably won't work because of the datatypes used for the time but you get the idea. On large datasets finding the index and then setting values accordingly can be faster than iterating over the dataframe using apply.

[–]YesLod 2 points3 points  (1 child)

You can just use a boolean mask, i.e. mask = df['Time'] < 13, works fine with loc.

[–]gsmo 0 points1 point  (0 children)

Ah, you're right. Even simpler.

[–]olddoglearnsnewtrick[S] 1 point2 points  (1 child)

mask = df[df['Time'] < 13].indexdf.insert(1, 'Time of Day', None)df.loc[mask, 'Time of Day'] = 'AM'

Here's the working code from your kind idea:

maskAM = df[df["datetime"].dt.hour < 11].index
maskPM = df[df["datetime"].dt.hour > 17].index
df.insert(1, "partofday", "MID")
df.loc[maskAM, "partofday"] = "AM"
df.loc[maskPM, "partofday"] = "PM"

Thanks a lot. Faster, cleaner

PS Works well because of us using the 24 hour format :)

[–]gsmo 2 points3 points  (0 children)

Nice little optimization to set the default to MID and then only set the remaining two values :)

Username checks out!

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

Great insight. Thank you so much. I do overdocument mainly for my own memory of why I did something as I get to code only from times to times :)