0
0
Data Analysis Pythondata~5 mins

Why Series is the 1D data structure in Data Analysis Python

Choose your learning style9 modes available
Introduction

A Series is called a 1D data structure because it holds data in a single line, like a list. It stores values with labels, making it easy to find and use data.

When you want to store a list of numbers or words with labels.
When you need to do simple calculations on a single column of data.
When you want to quickly access data by its label instead of position.
When you want to convert a list or dictionary into a labeled data structure.
When you want to prepare data before making a table (DataFrame).
Syntax
Data Analysis Python
import pandas as pd

# Create a Series from a list
s = pd.Series([10, 20, 30, 40])

# Create a Series with custom labels
s2 = pd.Series([10, 20, 30], index=['a', 'b', 'c'])

A Series holds data in one dimension, like a single column.

Each value has a label called an index, which helps to find data easily.

Examples
This creates a Series with default numeric labels (0, 1, 2).
Data Analysis Python
import pandas as pd

s = pd.Series([5, 10, 15])
print(s)
This creates a Series with custom labels 'x', 'y', 'z'.
Data Analysis Python
import pandas as pd

s = pd.Series([5, 10, 15], index=['x', 'y', 'z'])
print(s)
This creates a Series from a dictionary, using keys as labels.
Data Analysis Python
import pandas as pd

s = pd.Series({'apple': 3, 'banana': 5, 'cherry': 7})
print(s)
Sample Program

This program shows how a Series holds data in one dimension with labels. It also shows how to access data by label.

Data Analysis Python
import pandas as pd

# Create a Series with default index
numbers = pd.Series([100, 200, 300, 400])
print("Series with default index:")
print(numbers)

# Create a Series with custom index
fruits = pd.Series([10, 20, 30], index=['apple', 'banana', 'cherry'])
print("\nSeries with custom index:")
print(fruits)

# Access data by label
print("\nValue for 'banana':", fruits['banana'])
OutputSuccess
Important Notes

A Series is like a column in a spreadsheet with labels for each row.

It is simpler than a DataFrame, which has rows and columns (2D).

Labels (index) can be numbers, words, or dates.

Summary

A Series stores data in one dimension, like a list with labels.

It helps to organize and access data easily by using labels.

Series is the building block for more complex data structures like DataFrames.