본문 바로가기
대학교/데이터분석개론

5-1.Python Pandas_Series

by YS_LEE 2020. 6. 12.
반응형

준비물

import pandas as pd

from pandas import Series, DataFrame

 

Series 란? 

array같은 1차원 object

 

Series 생성

data = pd.Series([5000, 6000,7000, 8000])

coffee = pd.Series([5000600070006500], index=['americano''cappuccino''frappuccino''caffe latte'])

coffee2 = pd.Series({'Flat White'5500'Cold Brew'7000'Caffe Mocha'6500})

 

print(coffee)

>>>americano 5000

>>>cappuccino 6000

>>>frappuccino 7000

>>>caffe latte 6500

>>>dtype: int64

 

coffee.index

>>>Index(['americano', 'cappuccino', 'frappuccino', 'caffe latte'], dtype='object')

 

coffee['cappuccino'] 또는 coffee.cappuccino

>>>6000

 

coffee[:2]

>>>americano 5000

>>>cappuccino 6000

>>>dtype: int64

 

coffee*2

>>>

 

'caffe latte' in coffee_menu  

>>>True

 

Series: series name and index name

 

coffee_menu.name = 'starbucks'

>>>americano 5000

>>>cappuccino 6000

>>>frappuccino 7000

>>>caffe latte 6500

Name: starbucks, dtype: int64

 

coffee_menu.index.name = 'type'

type

americano 5000

cappuccino 6000

frappuccino 7000

caffe latte 6500

Name: starbucks, dtype: int64

 

coffee = ['ame''cap''frap''latte']   # index can be changed to an another index

반응형

'대학교 > 데이터분석개론' 카테고리의 다른 글

5-3.Python Pandas_DataCleaning  (0) 2020.06.12
5.2-Python Pandas_DataFrame  (0) 2020.06.12
4.Pyplot Visualization  (0) 2020.06.08
3.Python Numpy  (0) 2020.06.08
2.파이썬의 제어문, 함수  (0) 2020.06.08

댓글