Series
Pandas offers two primary data structures: Series
and DataFrame
. The Series
is the simpler of the two, resembling a one-dimensional array or a list. You can create a Series
object using the pd.Series()
constructor by passing a list as its argument.
9
1
2
3
4
5
import pandas as pd
numbers = [17, 43, 74, 20]
series = pd.Series(numbers)
print(series)
12345import pandas as pd numbers = [17, 43, 74, 20] series = pd.Series(numbers) print(series)
In this example, we use the pd.Series()
constructor to create a Series
object containing a list of numbers.
Task
Swipe to start coding
You are given two lists: even_numbers
and states
.
-
Create a
Series
namednumbers_series
from theeven_numbers
list. -
Create a
Series
namedstates_series
from thestates
list.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
import pandas as pd
even_numbers = [2, 4, 8, 16]
states = ['New York', 'California', 'Chicago', 'Alaska']
# Write your code below
numbers_series = pd.Series(even_numbers)
states_series = pd.Series(states)
# Testing the result
print(numbers_series , states_series)
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 2
99
1
2
3
4
5
6
7
8
9
10
11
import pandas as pd
even_numbers = [2, 4, 8, 16]
states = ['New York', 'California', 'Chicago', 'Alaska']
# Write your code below
numbers_series = ___
states_series = ___
# Testing the result
print(numbers_series , states_series)
Ask AI
Ask anything or try one of the suggested questions to begin our chat