CRUD and Pandas Exercises

Joe Olivare
5 min readOct 2, 2020

--

Again, our last week’s python class has been mind-stretching where everyone is like a sponge, determined to absorb every new lessons and full of brain efforts. Although it was tough, I’m pretty sure everyone in the class were driven by one goal — to become a certified “pythonista and data scientist”.

Anyways, two (2) key topics were discussed from last class, these were the CRUD (Create, Read, Update, Delete) and Pandas. To begin with, let me share to you first what I’ve learned and done using CRUD.

Movie Quiz Game with CRUD

If you have read my last blog (“Keeping up with Python”), I shared my owned quiz game using colab and spyder. This time, I’ve added some CRUD features based from what I’ve gained from our class.

Let me share my previous code I did. This is how I did my quiz game using Spyder.

Movie Quiz game code done in Spyder
Movie Quiz game code done in Spyder
Movie Quiz game code done in Spyder

If you look in to the codes, you will notice that there are no special features. Since the goal of this exercise is just to create a game that will print the player’s score results.

But for this, I created 2 player quiz game using jupyter by incorporating CRUD functions. Here’s my code looks like:

I’ve started with a dictionary, where I stored my questions and answer keys.

Then, I created def functions for each different executions.

This is where my added CRUD feature lies. I created a function that can delete, add and generate text file from actions.

I also added new feature time.sleep() by importing time that will add delays and smoothen the transitions of questions or spiel appearing. I added a 1.5 secs for each of these.

And here is the code output if you choose to play.

Then this code output if you choose to “Add or Remove”

Adding new question

Deleting question

As you add or remove a question, a text file based from your chosen action will appear from your file location.

Added question will appear. As you can see, my added question has been successfully added to dictionary.

Same with remove function. I intent to remove the question “A” and per below, it was successfully deleted.

And for the second part and last part of this blog, I’ll be sharing to you on how I code by importing Pandas.

Insurance Analysis using Pandas Python

This is actually my first meeting with Pandas and I’m still in a state of wilderness since most of my analysis and data cleaning to my current job were done using excel. However, when I did some exercises, I found this intriguing and new to me at the same time, which I like. So here’s what I did in Pandas using “Insurance regression data” as my practice.

The first thing I did was researching the different libraries related to Pandas and here’s what I did.

I imported pandas to enable access to different features and tools for data manipulation and data analysis. Then following by numpy that works with arrays and matrices and lastly, matplotlib for visualizaton tools.

Here are some filtering I did. From this example. I filtered the data per gender and count of age.

Then applying bar graph to visualize.

Same thing I did from above, I just filtered the values per gender, count of age and divided to smoker and non-smoker and convert into a table.

Then applying 2 bar graphs to compare number of smokers to non-smokers.

Dissecting the data into smaller insights and divided it into male and female by filtering smoker and non-smoker . Then I get the “mean” for each variables.

After exploring the data and possible insights, I created a scatter graph to visually check if there was a correlation between age and insurance charges.

I also created a line graph to see if being a smoker does have an effect to insurance cost.

Then lastly, I created a scatter graph matrix to inspect and compare other variables if correlated . You can import this by coding from pandas.plotting import scatter_matrices. (Thanks to Youtube tutorials! I was able to achieved this!)

You can check my github link for more details. That’s all for this week!

--

--

No responses yet