군침이 싹 도는 코딩

Python pandas Series 연산 본문

Python/Pandas

Python pandas Series 연산

mugoori 2022. 11. 23. 16:00

pandas Series 연산

index = ['apples', 'oranges', 'bananas']
data = [10, 6, 3,]

frults=pd.Series(data=data,index=index)
frults
>>> apples     10
    oranges     6
    bananas     3
    dtype: int64
    
# 전체 5개씩 증가되었다.
frults+5
>>> apples     15
    oranges    11
    bananas     8
    dtype: int64
    
    
# 오렌지가 2개 팔렸다
frults['oranges']-2
>>> apples     15
    oranges     9
    bananas     8
    dtype: int64
    
    
# 사과랑 바나나가 3개씩 팔렸다.
frults[['apples','bananas']] - 3 # 두개 이상일 경우 안에 리스트를 만들어서 입력한다.
>>> apples     12
    oranges     9
    bananas     5
    dtype: int64