Python logic

I’ve finished the first two modules on Python in DataCamp, the tool Techionista Academy uses for learning the basics. So far so good. It really helps that computer language is not completely alien to me. As a teenager I typed in tiny Basic examples from magazines to run silly programs. At university I started building websites form scratch in HTML and I can read and intervene in PHP thanks to years of experience using WordPress.

Getting properly introduced to Python really gives me better understanding of the logic of it. For instance when to use ‘ ‘ and when not. Or learning the difference between an integer and a float. Sometimes though, its logic is not that logical to me. One assignment asked me to select rows from a DataFrame (also known as a table). In this case the dataframe was a list of dogs with some attributes like age, dog breed and dog owner.

Lets call this DataFrame ‘dogs’. First task was to select dogs older than two.

greater_than_2 = dogs[dogs.Age > 2]

From dataframe ‘dogs’, select from column ‘Age’ everything larger than 2.

Next task was to select dogs who’s status was ‘still missing’.

still_missing = dogs[dogs.Status == 'Still Missing']

Easy enough when you know that ‘==’ means equal to.

Then the last task. Select dogs whose dog breed is not equal to poodle. More of the same, I thought. Although I already learned previously that you can’t use ‘dogs.XXX’ for referring to the right column in the table. This column name has two seperate wordes and therefore requires string notation. String notation means that it requires ‘ ‘. So I wrote:

not_poodle = dogs[dogs['Dog Breed' != 'Poodle']]

Running the code gave me an error. I tried many variations, but couldn’t find the mistake I was making. I had to ask for DataCamp to reveal the correct answer to me. It turned out that I had the second to last ] in the wrong place. The correct solution should have been:

not_poodle = dogs[dogs['Dog Breed'] != 'Poodle']

This felt totally unintuitive when I first read it. Now that I’m explaining it here, it starts to feel a bit more logical. I guess that’s what they call the learning curve. All languages have their own logic, which sometimes are in dissonance with the language you hear in your head.

Door |2021-01-30T15:35:23+02:0030 januari 2021|datascience, flow|1 Reactie

Back to school

Today I finally started my Data & AI course. I’ll be taking my first steps in learning Python and SQL. It will be an adventure to combine this time intensive course with work for clients, podcasting and Daughtertaining, but one way or the other I’ll manage. It’s not that there’s a lot of other stuff to do at night or during the weekend 😉

Door |2021-01-30T15:36:32+02:0026 januari 2021|datascience, flow|0 Reacties
Ga naar de bovenkant