728x90
반응형

파이썬프로그래밍 8

[pandas] pandas DataFrame 1

pandas DataFrame : 행과 열 import pandas as pd # We create a dictionary of Pandas Series items = {'Bob' : pd.Series(data = [245, 25, 55], index = ['bike', 'pants', 'watch']), 'Alice' : pd.Series(data = [40, 110, 500, 45], index = ['book', 'glasses', 'bike', 'pants'])} pd.DataFrame(data=items) # DataFrame = 2차원 데이터 / Series = 1차원 데이터 왼쪽 진한 글씨를 index 라고 하고 윗쪽 진한 글씨를 columns 라고 하고 안쪽 데이터 부분을 values 라고..

[pandas] pandas Series 데이터 1

pandas 데이터 분석 방법, 데이터 분석(처리) 라이브러리 기본적인 통계 데이터를 제공 pandas Series : 1차원 데이터 Series의 오른쪽 부분을 values(값)(data)라고 하고 Series의 왼쪽 부분을 index라고 한다. pandas Series 데이터 생성 import pandas as pd index = ['eggs', 'apples', 'milk', 'bread'] data = [30, 6, 'Yes', 'No'] index index[1] pandas Series pd.Series(data=data) 이때 인덱스 부분을 사람들이 보기 좋은 용도로 변경하고 싶을 때는 아래와 같이 index부분을 잡아준다. pd.Series(data=data, index=index) 변수 ..

[파이썬] 기초 다지기 함수 2

함수와 for 문 2 : zip(리스트 항목별 묶기, 일회용) (shell에서 실행하기) L1=['americano','caffe latte','espresso'] L2=[1500,2500,1600] z=zip(L1,L2) for coffee,price in z: coffee,price for coffee,price in z: coffee,price 무명 함수 : lambda(한줄짜리 함수) (shell에서 실행하기) f=lambda a,b:a*b f(10,20) f2=lambda a:a**2 f2(3) f3=lambda a:a>2 f3(3) lambda, map, for~in 문의 활용(map은 일회용) (shell에서 실행하기) f=lambda a:a**2 L=[1,2,3,4] for m in map..

[파이썬] 기초 다지기 리스트(list), 임의 문자열 생성

부분 항목 접근 : slicing (shell에서 실행하기) [0,1,2,3,4][0:1] [0,1,2,3,4][0:2] [0,1,2,3,4][1:3] [0,1,2,3,4][:3] [0,1,2,3,4][3:] [0,1,2,3,4][:] [0,1,2,3,4][1:4:2] [0,1,2,3,4][::2] 리스트 주요 함수 : len, sort, reverse, random, shuffle (shell에서 실행하기) import numpy as np np.random.seed(42) iList=[*np.random.randint(0,100,5)] iList len(iList) iList.sort() iList import random random.shuffle(iList) iList 임의 숫자 생성 : rand..

[파이썬] 기초 다지기 if 문

if 문 냉장고에서 사과 찾기 1 (shell에서 실행하기) fridge=["apple","pear","mandarine","banana"] where=fridge.index('apple') #index where apple=fridge.pop(where) #pop apple 냉장고에서 사과 찾기 2 (shell에서 실행하기) fridge=["apple","pear","mandarine","banana"] if 'apple' in fridge: where=fridge.index('apple') apple=fridge.pop(where) 'eat'+apple BMI 계산기 height=float(input('Enter your height in centimeters:')) weight=float(input..

[파이썬] 데이터 관리 : 간단한 데이터 관리

yo_price = 1800 #요구르트 가격 yo_qty = 4 #요구르트 판매량 milk_price = 1500 milk_qty = 2 #항목추가 hr_price = 1000 hr_qty = 3 yo_sales = yo_price*yo_qty milk_sales = milk_price*milk_qty #항목추가 hr_sales = hr_price*hr_qty total_sales = yo_sales+milk_sales+hr_sales total_qty = yo_qty+milk_qty+hr_qty print("드링킹 요구르트 매출액 : "+str(yo_sales)) print("딸기 우유 매출액 : "+str(milk_sales)) print("홈런공 매출액 : "+str(hr_sales)) print(..

728x90
반응형