Python
-
#6-1Python/Jupyter notebook 2023. 1. 16. 21:21
# 용례 1 class MyClass: i = 12345 def f(self): return 'hello world' MyClass.f(1) Out[2]: 'hello world' In [ ]: In [3]: class Complex: def __init__(self, realpart, imagpart): self.r = realpart self.i = imagpart # 다른 함수 선언 가능. 선언할 경우, r과 i를 사용 가능 # 그리고, 아래 셀의 코드처럼 counter 변수를 만들 경우, counter도 사용 가능 In [4]: x = Complex(3.0,-4.5) In [6]: x.i Out[6]: -4.5 In [7]: x.counter = 1 In [8]: while x.counter < ..
-
#5Python/Jupyter notebook 2023. 1. 16. 21:18
import pandas as pd In [2]: df = pd.DataFrame([1,2,3]) In [3]: df Out[3]: 0012 1 2 3 In [8]: df.to_csv('./asdf') In [7]: pd.read_csv('./asdf.csv') Out[7]: Unnamed: 00012 0 1 1 2 2 3 In [9]: import numpy as np In [13]: arr = np.array([1,2,3]) In [14]: arr Out[14]: array([1, 2, 3]) In [15]: arr[-1] Out[15]: 3 In [16]: arr[1:] Out[16]: array([2, 3]) In [17]: arr2 = np.array([4,5,6]) In [18]: arr + ..
-
#4Python/Jupyter notebook 2023. 1. 16. 21:13
def func1(x, y): # x, y를 입력받음 z = x % y # 연산 1 w = x - y # 연산 2 if z > w: # 조건에 따라 다른 리턴 return 'type I' else: return 'type II' In [3]: func1(4,3) Out[3]: 'type II' In [17]: result = func1(4,3) In [18]: result Out[18]: 'type II' In [10]: func1(9,99) Out[10]: 'type I' In [19]: x = 4 y = 3 In [20]: z = x % y # 연산 1 w = x - y # 연산 2 if z > w: # 조건에 따라 다른 리턴 result = 'type I' else: result = 'type II..
-
#3Python/Jupyter notebook 2023. 1. 16. 21:12
import math In [2]: math.log2(10) Out[2]: 3.321928094887362 In [3]: var1 = 123 In [4]: var1 Out[4]: 123 In [5]: import pandas as pd In [10]: df = pd.DataFrame([[1,2,3,4,5,6],[7,6,5,4,3,2]]) In [11]: df Out[11]: 01234501 1 2 3 4 5 6 7 6 5 4 3 2 In [16]: df[5][0] Out[16]: 6 In [18]: df.columns Out[18]: RangeIndex(start=0, stop=6, step=1) In [19]: df.index Out[19]: RangeIndex(start=0, stop=2, step=..
-
#2Python/Jupyter notebook 2023. 1. 16. 21:11
if (조건): (실행할 코드) In [ ]: if True: print('T') In [ ]: if 1: print('T') In [ ]: x = 70 if x > 50: print('T') In [ ]: x > 50 In [ ]: if 49: print('T') In [ ]: 49 == True In [ ]: 49 == False In [1]: while False: print(1) 반복문 while In [2]: ind = 0 while True: print('반복문이 실행되고 있습니다') ind += 1 if ind == 10: break 반복문이 실행되고 있습니다 반복문이 실행되고 있습니다 반복문이 실행되고 있습니다 반복문이 실행되고 있습니다 반복문이 실행되고 있습니다 반복문이 실행되고 있습니다..
-
#1Python/Jupyter notebook 2023. 1. 16. 21:07
'________AAAA________'.join(['hello','world']) Out[6]: 'hello________AAAA________world' In [7]: 'hello________AAAA________world'.split('________AAAA________') Out[7]: ['hello', 'world'] In [8]: 'AAAAAAAAAAAAAAAhelloAAAAAAAAAAA'.strip('A') Out[8]: 'hello' In [9]: 'AAA_+_+_+_AhelloAA_+_+_+_+A'.strip('A_+') Out[9]: 'hello' In [10]: 'AAA_+_+_+_AhelA_+loAA_+_+_+_+A'.strip('A_+') Out[10]: 'helA_+lo' I..