반응형
넘파이 어레이를 이용해서 데이터프레임 만들기¶
In [1]:
# 샘플 어레이 생성
import numpy as np
sample_array = np.random.randint(10, 15, (5,3))
sample_array
Out[1]:
array([[10, 10, 12],
[14, 10, 13],
[14, 10, 14],
[10, 14, 10],
[12, 12, 12]])
In [2]:
# 컬럼 및 인덱스 이름 생성
index_names = ["product_1", "product_2", "product_3", "product_4", "product_5"]
column_names = ["season_1", "season_2", "season_3"]
# 데이터 프레임 생성
import pandas as pd
df = pd.DataFrame(sample_array, index=index_names, columns=column_names)
df
Out[2]:
| season_1 | season_2 | season_3 | |
|---|---|---|---|
| product_1 | 10 | 10 | 12 |
| product_2 | 14 | 10 | 13 |
| product_3 | 14 | 10 | 14 |
| product_4 | 10 | 14 | 10 |
| product_5 | 12 | 12 | 12 |
반응형
'python' 카테고리의 다른 글
| load iris dataframe for sample data (0) | 2023.08.09 |
|---|---|
| check pytorch tensor size (0) | 2023.08.09 |
| 파이토치 어레이를 텐서 타입으로 array to tensor (0) | 2023.08.09 |
| matplotlib 그래프 위에 화살표 그리기 (0) | 2023.08.08 |
| matplotlib 을 활용한 도형 그리기 (0) | 2023.08.08 |
댓글