Pandas — DATAFRAMES

When should I use pandas DataFrame?#PySeries#Episode 31

J3
Jungletronics
5 min readMay 28, 2021

--

Let’s see Pandas' DATAFRAMES again! Google collab notebook link:)

Pandas DATAFRAMES: The Primary Pandas Data Structure!

Fig 0. Numpy & Pandas together!

When should I use pandas DataFrame?

The Pandas DataFrame is a structure that contains two-dimensional data and its corresponding labels.

DataFrames are widely used in data science, machine learning, scientific computing, and many other data-intensive fields.

What Follows Example of how to use it:

Please, open your collab notebook and follow me:

01# First thing first. Importing the libraries:

02# Let’s create a simple Graphic now:

Getting acquainted with PANDAS DATAFRAME:

3# Now here is a Real Problem:

4# Let’s Plot the Graph & Make a Linear Regression:

Creating The Graph’s Axis From Numpy Arrays(x & y):

Ice Cream Sales vs Temperature; Regression line: y=0.03x+6.41; Correlation Coefficient: r=0.96.

🍦As you can see, the temperature 🍧 boosts the sales for the ice screen 🍨

5# Now Pandas DATAFRAMES Operations:

DATAFRAMES Can be thought of as a dict-like container for Series objects.

Creating Pandas DATAFRAMES From Dictionary (X & Y):

DATAFRAME: Ice Cream Sales vs Temperature.

6# Pandas DATAFRAMES — Using Brackets Notation:

DATAFRAMES — The primary Pandas data dict-like container structure!

Getting specific Column LIKE THIS: df[‘Specific_column’]…

What type of object is it?

…or like this: df[[‘List_of_Columns’]]:

This is a DATAFRAME object!

Returning a SERIES object:

Returning a DATAFRAME object:

This is a DATAFRAME object!

7# Creating a New Column (X.Y):

Making a Multiple Operation with DATAFRAMES:

8# Dropping Columns:

When inplace = True, the data is modified in place, which means it will return nothing, and the dataframe is now updated.

When inplace = False (DEFAULT), which is the default, then the operation is performed and it returns a copy of the object. You then need to save it to something.

Now:

9# Dropping Rows:

Now with inplace attribute:

10# Selecting Rows — There are two methods:

LOC -> LABEL-BASE index

ILOC -> NUMERICAL-BASE index

Now:

11# Returning a Single Value:

12 # Returning a SUB-SET of the DataFrame:

13 # J3 signing-off ;):

I WISH YOU ALL THE BEST!

OK! That’s all!

I hope you enjoyed that lecture.

If you find this post helpful, please click the applause button and subscribe to the page for more articles like this one.

Until next time!

I wish you an excellent day!

31_pandas_dataframe_practice.ipynb

Credits & References

Based on: Support Vector Machines: A Visual Explanation with Sample Python Code by Alice Zhao

Related Post:

08 # PySeries#Episode 08 — Pandas — DataFrames : The Primary Pandas Data Structure! It Is a Dict-Like Container for Series Object

--

--

J3
Jungletronics

😎 Gilberto Oliveira Jr | 🖥️ Computer Engineer | 🐍 Python | 🧩 C | 💎 Rails | 🤖 AI & IoT | ✍️