A Python Library Specialized in Data Processing, Pandas
When working with data such as item sales or customer influx over time, it's typically organized in a table format with 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. However, in the practice environment, Pandas is already installed, so no additional installation is needed.
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.
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.
It contains both rows and columns, and each column can hold a different data type.
This structure is similar to an Excel table (spreadsheet).
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, 'Item': ['Apple', 'Banana', 'Strawberry', 'Grapes']
creates a Series resembling an Excel column, which is then combined with other Series to form the DataFrame.
Which word fits best in the blank?
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help