본문 바로가기

파이썬 기본

(10)
판다스 조인 In [2]: import pandas as pd In [48]: from IPython.core.display import display, HTML display(HTML("")) C:\Users\82105\AppData\Local\Temp\ipykernel_14852\3510566465.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display from IPython.core.display import display, HTML In [47]: from IPython.core.display import display..
판다스 그룹바이 In [2]: import pandas as pd In [47]: from IPython.core.display import display, HTML display(HTML("")) C:\Users\82105\AppData\Local\Temp\ipykernel_14852\3510566465.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display from IPython.core.display import display, HTML 테스트용 DataFrame 생성¶ In [3]: cust_dict = { 'custome..
시각화 기초 _ 학교수업 때 배운 부분 220914 In [ ]: #제곱근 구하는 첫 x는 input (x)는 아웃풋 import math makesqr= lambda x: math.sqrt(x) num = int(input('수 입력>>>')) print(f'{num}의 제곱근은 {makesqr(num)}이다') 수 입력>>>5 5의 제곱근은 2.23606797749979이다 filter()함수 처리된 각각의 요로에 대하여 boolian값 반환 트루를 반환하면 그요소는 남게 되고 펄스를 반환하면 그요소는 제거 결국 주어진 조건을 만족하는 요소를 구히는 함수 In [ ]: import random import numpy as np In [ ]: np.random.seed(0) # seed (0) 은 랜덤함수를 썻지만 같은수만 출력할때 사용 a..
간단한 데이터 전처리 특정 행 조회 등등 In [256]: import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt import csv In [257]: df = pd.read_csv('work.csv', encoding = 'cp949') df Out[257]: 국가별 1995 1995.1 1995.2 1996 1996.1 1996.2 1997 1997.1 1997.2 ... 2016.2 2017 2017.1 2017.2 2018 2018.1 2018.2 2019 2019.1 2019.2 0 국가별 전체 남자 여자 전체 남자 여자 전체 남자 여자 ... 여자 전체 남자 여자 전체 남자 여자 전체 남자 여자 1 아시아 NaN NaN Na..
행열전환 함수 + 컬럼을 행데이터로 바꾸기 transpose() In [2]: import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt import csv In [42]: df1 = pd.read_csv('sss.csv', encoding = 'cp949') df1 Out[42]: 년도 1995 1996 1997 1998 1999 2000 2001 2002 2003 ... 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 0 대한민국 54.8 57.5 60.1 64.6 65.1 66.6 69.3 71.2 73.7 ... 94.7 96.8 98.0 99.3 100.0 101.0 102.9 104.5 104.9 105.4 1..
기본 그래프 그려보기 In [2]: import matplotlib.pyplot as plt #%matplotlib inline plt.plot([1, 2, 3], [2, 4, 6]) plt.title("Hello plot") plt.show() In [ ]: Figure와 Axes¶ In [3]: # plt.figure()는 주로 figure의 크기를 조절하는 데 사용됨. plt.figure(figsize=(10, 4)) # figure 크기가 가로 10, 세로 4인 Figure객체를 설정하고 반환함. plt.plot([1, 2, 3], [2, 4, 6]) plt.title("Hello plot") plt.show() In [4]: figure = plt.figure(figsize=(10, 4)) print(type(fig..
프로그램 활용을 통한 클래스 선언만들기 In [1]: ## class 선언 만들기 In [2]: class Travel: #클래스 선언 INDIVIDUAL = 1 # 클래스 변수 선언 PACKAGE=0 #생성되는 객체의 속성(인스턴스)변수를 초기화하는생성자 매소드 def __init__(self,travelCode, cityName, flight , travelType, maxPeople,reserved): self.travelCode= travelCode self.cityName= cityName self.flight= flight self.travelType= travelType self.maxPeople = maxPeople self.reserved = reserved #부모 클래스 object로부터 상속받은 메소드를 재정의(overri..
문자열 함수 이용해보기 문자열 관련 함수 알아보기¶ 문자열에 있는 특정 문자 갯수 세기 (count 함수)¶ In [1]: data = 'Dave David' data.count('D') # 문자열에 D 가 몇 번 나올까요? 대소문자도 구별함 Out[1]: 2 간단 연습: string에 v 는 몇 번 나올까? 간단 연습: string에 vid 는 몇 번 나올까? (꼭 문자 하나만 되는 것이 아니라, 연결된 문자열도 가능) 문자열에 있는 특정 문자의 위치 알려주기¶ index 함수¶ In [7]: string = 'Dave ID is dave' string.index('i') # 맨 앞 자리부터 0, 1, ... 순으로 위치를 표시 Out[7]: 8 간단 연습: string에 있는 D의 위치 확인하기 (가장 먼저 나오는 위치를 ..