Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

A Python Library Specialized in Data Processing, Pandas

When dealing with data like sales per item, or customer influx over time, these data points are generally expressed in table format consisting of rows (horizontal) and columns (vertical).

Pandas is one of the most widely used packages in Python for handling tabular data.

With Pandas, you can systematically perform a variety of tasks—from basic operations like loading and saving data to more complex ones like filtering, sorting, and statistical analysis.


Installing Pandas

You can install Pandas using the following command. In the practice environment, Pandas is already installed, so separate installation is not necessary.

Install Pandas
pip install pandas

Two Data Structures of Pandas

The core data structures of Pandas are Series and DataFrame.


1. Series

A Series is a one-dimensional data structure, conceptually similar to a single column in Excel.

Data is arranged sequentially, similar to a Python list (array).

Each piece of data has a unique index (identifier indicating the position of the data), through which the data can be accessed.

Example of Creating a Series
import pandas as pd

# Create a series
data_series = pd.Series([10, 20, 30, 40])

print(data_series)
# Output
# 0 10
# 1 20
# 2 30
# 3 40
# dtype: int64

2. DataFrame

A DataFrame is a two-dimensional data structure composed of multiple Series.

Both rows and columns exist, and each column can have different data types.

This structure is similar to an Excel table (spreadsheet).

Example of Creating a DataFrame
import pandas as pd

# Create a DataFrame for sales by item
data_frame = pd.DataFrame({
'Item': ['Apple', 'Banana', 'Strawberry', 'Grapes'],
'Sales': [1000, 2000, 1500, 3000]
})

print(data_frame)
# Output
# Item Sales
# 0 Apple 1000
# 1 Banana 2000
# 2 Strawberry 1500
# 3 Grapes 3000

In the example above, the DataFrame is created with columns labeled 'Item' and 'Sales'.

For instance, the code that creates the DataFrame 'Item': ['Apple', 'Banana', 'Strawberry', 'Grapes'] generates a series (Series) similar to a column in Excel (a vertical line), which is then combined to form the DataFrame.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.