Protecting Employees

US companies are starting to take precautions due to the unpredictable and growing spread of COVID-19, also known as the coronavirus. It’s no surprise that international travel restrictions are…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Jupyter Notebook like a G

I realized that Python lovers don’t necessarily like to code in an object oriented way, instead they have a very linear, notebook style flow to their processes. This is why Jupyter Notebook has become super popular for those who like to code Python. Here we are going to explore some Python and the most adopted environment to code Python in for running algorithms and things more Data-Science-y.

First each block of code can be run independently by pressing shift + enter. Try it with this code:

When we hit shift + enter it will show the output of this block directly underneath it. We can write code in Jupyter Notebook or we can switch to Markdown to write notes instead of writing in code. We can also import our libraries anywhere in the file just like we would for Ruby.

What’s cool is we can also run terminal commands within the notebook instead of in the terminal, I.E: ls, pwd etc. There is also the ability to be in command mode and edit mode by hitting the escape key to get into command mode to do things like select code and copy and paste. Then hit the Enter key to get right back into edit mode. The keyboard shortcuts are given to us in the Help menu bar item.

Just like any other code file you can load in csv files. This is very important as the beauty of Python is it’s computational speed to process and manipulate lots of data at a high speed. Here we are going to load Donald Trump’s most favorited tweets.

We use our pandas package to read csv files and then when we execute this code we get this output

Because we are using a package and have already imported it in we can also see what methods are available to it similar to what we would do in VS code by hitting “tab” after the dot. This shows us everything we can do with Pandas. Pretty cool, because we didn’t even need to download an extra package like in VS code, it just came out of the box with Jupyter notebook.

Do you ever wonder what options you can pass to a method? Well you can just write the method and then add a question mark after to see all the options immediately under it. So if we have no idea what the head method is for the data frame we can type this:

And it will spit out the documentation with examples, so we know how to use it and what it’s doing:

Now we know this method returns the first 5 rows of the dataframe. Neat! We can use this to manipulate the data however we want just like Ruby! We can call a column name on the attribute to just get the specific column and we can slice it in python too.

This will return Trump’s first five tweet’s in the data set. Pretty similar syntax to Ruby. We could also use bracket notation just like Ruby. The other cool thing about Python is they have great libraries for graphs. We could download those and create cool charts using a package like matplotlib. But this dataset doesn’t really make any sense to do that with. The End.

Add a comment

Related posts:

5 websites a computer science student should know

MIRO is an online collaborative whiteboard platform, that will help you to work with your team anytime and anywhere. I’ve been using miro for 3 months now and it makes my work efficient. ProductHunt…

How a 15 year old indian student can learn and get AWS cloud certification

AWS Cloud Practitioner Essentials is an introductory-level course that covers the fundamentals of AWS Cloud, including cloud concepts, security, pricing, and billing. AWS Technical Essentials is…

The Life and Legacy of Cheikh Anta Diop

Cheikh Anta Diop was born on December 29, 1923, in Diourbel, Senegal, which was then a French colony. He was the son of an Islamic scholar and was raised in a deeply religious household. From a young…