0Pricing
Pandas & NumPy Academy · 강의

Series 만들기

Python 리스트, dict, NumPy 배열로 Pandas Series를 만들고 index 및 values 속성을 확인합니다.

Series 만들기은(는) CoddyKit의 무료 Pandas & NumPy Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Pandas & NumPy Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Pandas & NumPy Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What Is a Pandas Series?

A Pandas Series is a one-dimensional labelled array capable of holding any data type — integers, floats, strings, Python objects, or even other Series. Think of it as a NumPy array with a custom index (labels for each element). The index is what makes Series much more powerful than plain arrays for data analysis tasks where values need descriptive names.

import pandas as pd
import numpy as np

s = pd.Series([10, 20, 30, 40])
print(s)
# 0    10
# 1    20
# 2    30
# 3    40
# dtype: int64

Creating a Series from a Python List

Passing a Python list to pd.Series() creates a Series with a default integer RangeIndex (0, 1, 2, ...). You can provide custom index labels via the index= parameter. The length of the index list must match the length of the data. Labels can be strings, integers, dates, or any hashable Python objects.

import pandas as pd

temps = pd.Series([22.5, 19.0, 25.3, 17.8],
                  index=['Mon', 'Tue', 'Wed', 'Thu'])
print(temps)
# Mon    22.5
# Tue    19.0
# Wed    25.3
# Thu    17.8
# dtype: float64

Creating a Series from a Dictionary

A Python dict can be passed directly to pd.Series(). The dict keys become the index labels and the values become the data. This is one of the most natural ways to create a Series when your data already has meaningful labels. The resulting Series is ordered by the dict's insertion order (Python 3.7+).

import pandas as pd

stock = {'AAPL': 182.5, 'GOOG': 141.3, 'MSFT': 378.9}
s = pd.Series(stock)
print(s)
# AAPL    182.5
# GOOG    141.3
# MSFT    378.9
# dtype: float64

Creating a Series from a NumPy Array

A NumPy ndarray can be passed as the data argument. The dtype of the Series matches the ndarray's dtype. The underlying data is stored as a NumPy array, so all NumPy ufuncs work directly on Series. This makes it easy to migrate existing NumPy code to Pandas without rewriting data preparation logic.

import pandas as pd
import numpy as np

arr = np.linspace(0, 1, 5)
s = pd.Series(arr, index=['a', 'b', 'c', 'd', 'e'])
print(s)
# a    0.00
# b    0.25
# c    0.50
# d    0.75
# e    1.00

The .index and .values Attributes

s.index returns the Index object containing the labels. s.values returns the underlying NumPy array of data values. Both are essential for interoperability: you can pass s.values to any NumPy function and convert the result back to a Series with the original index. s.dtype gives the data type of the values.

import pandas as pd

s = pd.Series([3, 1, 4], index=['x', 'y', 'z'])
print(s.index)   # Index(['x', 'y', 'z'], dtype='object')
print(s.values)  # [3 1 4]
print(s.dtype)   # int64

Series Name and Index Name

A Series can have a .name attribute describing what the values represent, and its index can have a .name attribute describing what the labels represent. These names appear in DataFrames when a Series is assigned to a column, and in plot labels. Set them with s.name = 'price' or at creation with name=.

import pandas as pd

s = pd.Series([1.2, 3.4, 5.6],
              index=['a', 'b', 'c'],
              name='measurement')
s.index.name = 'label'
print(s)
# label
# a    1.2
# b    3.4
# c    5.6
# Name: measurement, dtype: float64

Creating a Scalar Series

Passing a single scalar value to pd.Series() with an explicit index creates a Series where every element equals that scalar. This is similar to NumPy's np.full() and is handy for creating constant baseline Series to subtract from or compare with a real data Series.

import pandas as pd

s = pd.Series(5, index=['a', 'b', 'c', 'd'])
print(s)
# a    5
# b    5
# c    5
# d    5
# dtype: int64

Automatic Index Alignment

One of the most powerful features of Pandas Series is automatic index alignment. When you add two Series, Pandas aligns them by their labels before computing the result. If a label exists in one Series but not the other, the result at that label is NaN. This prevents silent off-by-one errors common with NumPy array operations.

import pandas as pd

a = pd.Series([1, 2], index=['x', 'y'])
b = pd.Series([10, 20], index=['y', 'z'])
print(a + b)
# x     NaN
# y    12.0
# z     NaN

Checking Series Length and Shape

len(s) returns the number of elements. s.shape returns a tuple (n,) consistent with NumPy conventions. s.size is the same as len(s). Use these checks at the start of a pipeline to validate that your data loading produced the expected number of rows before proceeding with analysis.

import pandas as pd

s = pd.Series(range(10))
print(len(s))     # 10
print(s.shape)    # (10,)
print(s.size)     # 10
print(s.ndim)     # 1

Converting a Series to Other Types

You can convert a Series back to a Python list with s.tolist(), to a NumPy array with s.to_numpy() or s.values, and to a dict with s.to_dict(). These conversions are useful for interoperability with libraries that do not accept Pandas objects and for serialising results to JSON or CSV.

import pandas as pd

s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s.tolist())      # [10, 20, 30]
print(s.to_numpy())    # [10 20 30]
print(s.to_dict())     # {'a': 10, 'b': 20, 'c': 30}

Series vs DataFrame Column

A single column of a DataFrame is a Series. When you access df['col'], Pandas returns a Series with the same index as the DataFrame. Conversely, a Series with a name can be inserted into a DataFrame as a column directly. Understanding this relationship helps you move fluidly between Series and DataFrame operations.

import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
col = df['a']           # Series
print(type(col))        # <class 'pandas.core.series.Series'>
print(col.values)       # [1 2 3]

Quick Check

Test your understanding of creating Pandas Series from this lesson.

Lesson Recap

In this lesson you learned: a Series is a 1-D labelled array built on a NumPy ndarray, it can be created from lists, dicts, NumPy arrays, or scalars, and index alignment automatically handles label-based arithmetic between two Series. Next up we cover accessing Series elements by label with .loc and by position with .iloc.

자주 묻는 질문

“Series 만들기” 강의는 무료인가요?

네 — “Series 만들기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Pandas & NumPy Academy 강의 전체를 잠금 해제할 수 있습니다. Pandas & NumPy Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“Series 만들기”에서 뭘 배우나요?

Python 리스트, dict, NumPy 배열로 Pandas Series를 만들고 index 및 values 속성을 확인합니다. 브라우저에서 직접 실행하는 실습 코드로 Pandas & NumPy Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Pandas & NumPy Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Pandas & NumPy Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“Series 만들기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Pandas & NumPy Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Pandas & NumPy Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Series 만들기
  2. 레이블 기반 및 위치 기반 접근
  3. Series의 벡터화 연산
  4. 유용한 Series 메서드
← Pandas & NumPy Academy(으)로 돌아가기