Skip to content

Commit 00bed42

Browse files
authored
Create part_1_series_intro.py
1 parent 5265cfc commit 00bed42

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Part 1: Introduction to Series
2+
3+
import pandas as pd
4+
5+
# Example 1: Creating a Series from a list
6+
# The index is automatically generated (0, 1, 2...)
7+
data_list = [10, 20, 30, 40]
8+
series_a = pd.Series(data_list)
9+
print("Series from a list:")
10+
print(series_a)
11+
12+
# Example 2: Creating a Series from a dictionary
13+
# The dictionary keys become the index
14+
data_dict = {'New York': 150, 'Los Angeles': 50, 'Chicago': 250}
15+
series_b = pd.Series(data_dict)
16+
print("\nSeries from a dictionary:")
17+
print(series_b)
18+
19+
# Example 3: Accessing elements
20+
print(f"\nValue at position 1 (list series): {series_a[1]}")
21+
print(f"Value for 'Chicago' (dict series): {series_b['Chicago']}")

0 commit comments

Comments
 (0)