34

Using the Pandas Data Frame as a Database.

 4 years ago
source link: https://www.tuicool.com/articles/7fUzQvA
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Let us understand how to use the pandas data frame as a database.

mu6NFvn.jpg!web

Image Credits: Usejournal

Before starting let me quickly tell about the pandas data frame: It is a python library that provides high performance, and easy-to-use data structure for data analysis tools for python programming language. Below is an article that explains the primitive manipulations performed on the pandas data frame.

Let’s get started, this is a programming tutorial so I recommend you guys to practice side by side with me. I favor using Google Colab or Jupyter notebooks. To brief out, I will teach you guys how to use the pandas data frame as a database to store data and perform some rudimentary operations on it. This data frame has almost all the features compared to a database. It almost resembles a database.

Steps that will be followed in this tutorial are

  1. Creating a pandas data frame

2. Adding a row to the data frame

3. Deleting a row from the data frame

4. Accessing the value of a row from the data frame

5. Changing the value of a row in the data frame

Let see how can we perform all the steps declared above

1. Creating a pandas data frame

To create the data frame, first you need to import it, and then you have to specify the column name and the values in the order shown below:

import pandas as pd

Let’s create a new data frame. I am storing the company name, Founders, Founded and Number of Employees. You can store the data of your choice inside the data frame.

df = pd.DataFrame({‘Company Name’:[‘Google’, ‘Microsoft’, ‘SpaceX’,‘Amazon’,‘Samsung’]‘Founders’:[‘Larry Page, Sergey Brin’, ‘Bill Gates, Paul Allen’,’Elon Musk’,’Jeff Bezos’, ‘Lee Byung-chul’],‘Founded’: [1998, 1975, 2002, 1994, 1938],‘Number of Employees’: [‘103,459’, ‘144,106’, ‘6,500’, ‘647,500’, ‘320,671’]})df # used to print the data frame df, or use print(df) both are same

NJV7FnA.png!web

Don’t worry there is nothing complicated here, it’s just the values that might confuse you as they are just Company name, founders, founded, etc. Be careful with the brackets it can make your life miserable if you mess with it.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK