Skip to main content

Command Palette

Search for a command to run...

different types of Data Structures in Pandas?

Published
•1 min read•View as Markdown
B
Senior Software Engineer | Backend, Cloud, Data, Machine Learning

In Pandas, there are two main data structures: Series and DataFrame.

  1. Series: A Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating-point numbers, Python objects, etc.). The axis labels are collectively referred to as the index. A Series can be created using the pd.Series() function.

Example:

import pandas as pd
data = pd.Series([1, 2, 3, 4])
print(data)

Output:

0    1
1    2
2    3
3    4
dtype: int64
  1. DataFrame: A data frame is a 2-dimensional labeled data structure with columns of potentially different types. It is like a spreadsheet or SQL table, or a dict of Series objects. It is generally the most commonly used Pandas object. A data frame can be created using the pd.DataFrame() function.

Example:

import pandas as pd
data = {'name': ['Alice', 'Bob', 'Charlie', 'David'], 'age': [25, 30, 35, 40]}
df = pd.DataFrame(data)
print(df)

Output:

       name  age
0     Alice   25
1       Bob   30
2   Charlie   35
3     David   40

In addition to these two main data structures, Pandas also provides other data structures such as Panel, Panel4D, and PanelND, which are less commonly used.

More from this blog

yesicbap

437 posts