Skip to content

kamzzang/TIL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

90 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Today I learned

2020.02.09

Git basic command

  • git init:Initialize repositury
  • .git : repository
  • git status : working tree status
  • git add : add to staging area
  • git add . : add all files to staging area
  • git commit : create version
  • git commit -m "Message"
  • git commit -am "Message" : add + commit
  • git log : show version
  • git log -stat
  • git log -p
  • git diff
  • git checkout commit-ID
  • git checkout master

Change git editor

  • git config --global core.editor "nano"

Reset

  • git reset --hard commit-ID
  • git reset --soft commit-ID

Display log(branch)

  • git log --all --grape -- oneline

Correct coCcommit massage

  • git commit --amend

2020.03.12

Git remote

  • git init
  • git remote add origin "http adress"
  • git pull origin master
  • git add *
  • git commit -m "Message"
  • git push --set-upstream origin master

2020.03.20

pyc compile(pyc_compile.py)


import py_compile  
py_compile.compile('py file name')

bat file(2 python versions)

C:\Anaconda3\python.exe pyc_compile.py
C:\Anaconda3\envs\python36\python.exe pyc_compile.py

2020.03.23

DataFrame Error Fix


import pandas as pd  
df = pd.DataFrame({'col_1': 1, 'col_2': 2})

  • add an index

df = pd.DataFrame({'col_1':1, 'col_2':2}, index=[0])

  • use a list instead of scalar values

df = pd.DataFrame({'col_1':[1], 'col_2':[2]})

  • use pd.DataFrame.from_records() with a list

df = pd.DataFrame.from_records([{'col_1':1, 'col_2':2}])

  • use pd.DataFrame.from_dict([]) with a list

df = pd.DataFrame.from_doct([{'col_1':1, 'col_2':2}])

2020.03.27

๋™์  ๋ณ€์ˆ˜ ์ƒ์„ฑ


data = ["first", "second", "third"]
for name in data:
    for i in range(1,4):
        globals()[name] = [x*i for x in range(3)]

2020.03.28

json ํŒŒ์ผ ์ƒ์„ฑ


import json

with open('?????.json', 'w', encoding='utf-8') as make_file:

    json.dump(json_data, make_file, indent="\t")

json ํŒŒ์ผ open


import json

with open('?????.json', 'r') as f:

    admin_info = json.load(f)

print(admin_info)

ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ


import os

admin_info_file = os.getenv('NAME')

2020.04.02

Numpy Zero-like


>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.zeros_like(x)
array([[0, 0, 0],
       [0, 0, 0]])

2020.04.12

Folium Marker icon ref.

2020.04.15

AWS SSH ์—ฐ๊ฒฐ

cmd / powershell ๊ด€๋ฆฌ์ž๋ชจ๋“œ๋กœ ์‹คํ–‰
ssh -i "AWSKEY.pem" ubuntu@ec2-IP์ฃผ์†Œ.ap-northeast-2.compute.amazonaws.com

AWS server ๊ตฌ๋™

  1. python3 application.py : ํŒŒ์ด์ฌ ์„œ๋ฒ„ ๊ตฌ๋™
  2. Ctrl + Z : ํ”„๋กœ์„ธ์Šค ์ค‘์ง€
  3. bg : ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์„œ๋ฒ„ ๋‹ค์‹œ ๊ตฌ๋™
  4. disown -h : ์†Œ์œ ๊ถŒ ํฌ๊ธฐ

์ค‘์ง€

  1. netstat -nap | grep {ํฌํŠธ ๋ฒˆํ˜ธ}: ํŠน์ • ํฌํŠธ ๋ฒˆํ˜ธ์—์„œ ๋Œ์•„๊ฐ€๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ํ™•์ธํ•˜๊ธฐ
  2. kill -9 {ํ”„๋กœ์„ธ์Šค ๋ฒˆํ˜ธ}: ํŠน์ •ํ•œ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ข…๋ฃŒ์‹œํ‚ค๊ธฐ

์ถ”๊ฐ€

  1. jobs : ํ”„๋กœ์„ธ์Šค ํ™•์ธ
  2. fg : ํฌ์–ด๊ทธ๋ผ์šด๋“œ

keyํŒŒ์ผ์—†๋Š” PC์—์„œ ์›๊ฒฉ ์—ฐ๊ฒฐ(homepage)

  1. ssh [email protected]
  2. PASSWORD
  3. python3 application.py
  4. Ctrl + Z
  5. bg
  6. disown -h

2020.04.16

KAKAO MAPS API

  • Geocoding

url = 'https://dapi.kakao.com/v2/local/search/address.json?query='+addr
headers = {"Authorization": "KakaoAK {Private Key}"}
result = json.loads(str(requests.get(url,headers=headers).text))

if len(result['documents']) !=0:
    match_first = result['documents'][0]['address']
    return float(match_first['y']),float(match_first['x'])
else:
    return None, None

2020.05.07

install python anaconda 32bit envs

  • set CONDA_FORCE_32BIT=1
  • conda create -n XXXXXXX python=3.7 anaconda

To activate envs.

  • conda activate XXXXXXX

To deactivate an active envs.

  • conda deactivate

2020.05.18

pandas string


# ๊ณต๋ฐฑ ์ œ๊ฑฐ
df['email_strip']  = df['email'].str.strip()  # ์•ž ๋’ค ๊ณต๋ฐฑ์„ ์ œ๊ฑฐ
df['email_lstrip'] = df['email'].str.lstrip() # ์•ž ๊ณต๋ฐฑ์„ ์ œ๊ฑฐ
df['email_rstrip'] = df['email'].str.rstrip() # ๋’ค ๊ณต๋ฐฑ์„ ์ œ๊ฑฐ

# split(): ๊ตฌ๋ถ„์ž๋ฅผ ๊ธฐ์ค€์œผ๋กœ n๊ฐœ๋กœ ๋‚˜๋ˆˆ๋‹ค, expand=True์ด๋ฉด ์—ฌ๋Ÿฌ ์ปฌ๋Ÿผ, False์ด๋ฉด 1๊ฐœ ์ปฌ๋Ÿผ์— ๋ฆฌ์ŠคํŠธ
df[['email_split_1', 'email_split_2']] = df['email'].str.split('@', n=1, expand=True)

# ์น˜ํ™˜
df['email_lower']      = df['email'].str.lower()      # ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ
df['email_upper']      = df['email'].str.upper()      # ๋ชจ๋‘ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ
df['email_capitalize'] = df['email'].str.capitalize() # ์•ž๋ฌธ์ž ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ
df['email_title']      = df['email'].str.title()      # ๋‹จ์œ„๋ณ„ ์•ž๋ฌธ์ž ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ
df['email_swapcase']   = df['email'].str.swapcase()   # ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž, ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ 

# ์ž…๋ ฅ ํŒจํ„ด ๋˜๋Š” ๊ธ€์ž๋ฅผ ๋Œ€์ฒด, ์˜ˆ์ œ์—์„œ๋Š” .์„ _๋กœ ๋ณ€๊ฒฝ
df['email_replace']    = df['email'].str.replace(pat='.', repl='_', regex=False)

# ๋ฌธ์ž์—ด์˜ ์œ„์น˜(์ธ๋ฑ์Šค)
df['email_find']    = df['email'].str.find(sub='.')           # ์™ผ์ชฝ๋ถ€ํ„ฐ sub๊ฐ’ ๊ฒ€์ƒ‰ํ›„ ์œ„์น˜๋ฐ˜ํ™˜
df['email_findall'] = df['email'].str.findall(pat='[a-zA-Z]') # ์ฐพ์€ ๋ชจ๋“  ๊ฐ’ ๋ฐ˜ํ™˜
df['email_rfind']   = df['email'].str.rfind(sub='.')          # ์˜ค๋ฅธ์ชฝ๋ถ€ํ„ฐ sub๊ฐ’ ๊ฒ€์ƒ‰ํ›„ ์œ„์น˜๋ฐ˜ํ™˜
df['email_index']   = df['email'].str.index(sub='.')          # ์™ผ์ชฝ๋ถ€ํ„ฐ sub๊ฐ’ ๊ฒ€์ƒ‰ํ›„ ์œ„์น˜๋ฐ˜ํ™˜
df['email_rindex']  = df['email'].str.rindex(sub='.')         # ์˜ค๋ฅธ์ชฝ๋ถ€ํ„ฐ sub๊ฐ’ ๊ฒ€์ƒ‰ํ›„ ์œ„์น˜๋ฐ˜ํ™˜

# ๊ธธ์ด ๋ฐ˜ํ™˜
df['email_len']   = df['email'].str.len()              

# ๊ตฌ์„ฑ ํ™•์ธ
df['email_isalnum']   = df['email'].str.isalnum()   # ์•ŒํŒŒ๋ฒณ ๋˜๋Š” ์ˆซ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isalpha']   = df['email'].str.isalpha()   # ์•ŒํŒŒ๋ฒณ์œผ๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isdecimal'] = df['email'].str.isdecimal() # ์ˆซ์ž๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isdigit']   = df['email'].str.isdigit()   # ์ˆซ์ž๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_islower']   = df['email'].str.islower()   # ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isnumeric'] = df['email'].str.isnumeric() # ์ˆซ์ž๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isspace']   = df['email'].str.isspace()   # ๊ณต๋ฐฑ(Whitespace)์œผ๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_istitle']   = df['email'].str.istitle()   # TitleCaseํ˜•ํƒœ๋กœ ๊ตฌ์„ฑ ์—ฌ๋ถ€
df['email_isupper']   = df['email'].str.isupper()   # ๋Œ€๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ ์—ฌ๋ถ€

# ๋ฌธ์ž์—ด ํŒจํ„ด
df['email_startswith'] = df['email'].str.startswith(pat='h')     # ์ขŒ์ธก๊ฐ’์ด ์ž…๋ ฅํŒจํ„ด๊ณผ ์ผ์น˜ ์—ฌ๋ถ€
df['email_endswith']   = df['email'].str.endswith(pat='com')     # ์šฐ์ธก๊ฐ’์ด ์ž…๋ ฅํŒจํ„ด๊ณผ ์ผ์น˜ ์—ฌ๋ถ€
df['email_contains']   = df['email'].str.contains(pat='kr', regex=False) # ๊ฐ’ ์ค‘ ํŒจํ„ดํฌํ•จ ์—ฌ๋ถ€
df['email_match']      = df['email'].str.match(pat='[a-zA-Z@.]') # ์ž…๋ ฅํŒจํ„ด๊ณผ ์ผ์น˜ ์—ฌ๋ถ€

2020.05.19

OS Module


# ํŒŒ์ผ ๋ชฉ๋ก ์–ป๊ธฐ
glob.glob(wildcard) # ์œ ๋‹‰์Šค ๊ฒฝ๋กœ๋ช… ํŒจํ„ด ์Šคํƒ€์ผ๋กœ ํŒŒ์ผ ๋ชฉ๋ก์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.
os.listdir(path) # ์ง€์ •๋œ ๋””๋ ‰ํ† ๋ฆฌ์˜ ์ „์ฒด ํŒŒ์ผ ๋ชฉ๋ก์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.
dircache.listdir(path) # os.listdir(path)์™€ ๋™์ผํ•œ ํŒŒ์ผ ๋ชฉ๋ก์„ ์ „๋‹ฌํ•œ๋‹ค.

# ๋””๋ ‰ํ† ๋ฆฌ ๋‹ค๋ฃจ๊ธฐ
os.chdir(path) #์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ ๋ณ€๊ฒฝ
os.getcwd() # ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์–ป๊ธฐ

# ํŒŒ์ผ ์ด๋ฆ„ ๋‹ค๋ฃจ๊ธฐ
os.path.abspath(filename) # ํŒŒ์ผ์˜ ์ƒ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ ๋ฐ”๊พธ๋Š” ํ•จ์ˆ˜
os.path.exists(filename) # ์ฃผ์–ด์ง„ ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜
os.curdir() # ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ ์–ป๊ธฐ
os.pardir() # ๋ถ€๋ชจ ๋””๋ ‰ํ† ๋ฆฌ ์–ป๊ธฐ
os.sep() # ๋””๋ ‰ํ† ๋ฆฌ ๋ถ„๋ฆฌ ๋ฌธ์ž ์–ป๊ธฐ

# ๊ฒฝ๋กœ๋ช… ๋ถ„๋ฆฌํ•˜๊ธฐ
os.path.basename(filename) # ํŒŒ์ผ๋ช…๋งŒ ์ถ”์ถœ
os.path.dirname(filename) # ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ ์ถ”์ถœ
os.path.split(filename) # ๊ฒฝ๋กœ์™€ ํŒŒ์ผ๋ช…์„ ๋ถ„๋ฆฌ
os.path.splitdrive(filename) # ๋“œ๋ผ์ด๋ธŒ๋ช…๊ณผ ๋‚˜๋จธ์ง€ ๋ถ„๋ฆฌ (MS Windows์˜ ๊ฒฝ์šฐ)
os.path.splitext(filename) # ํ™•์žฅ์ž์™€ ๋‚˜๋จธ์ง€ ๋ถ„๋ฆฌ

2020.05.21

datetime


import datetime
 
now = datetime.datetime.now()
print(now)          # 2018-07-28 12:11:32.669083

nowDate = now.strftime('%Y-%m-%d')
print(nowDate)      # 2018-07-28
 
nowTime = now.strftime('%H:%M:%S')
print(nowTime)      # 12:11:32
 
nowDatetime = now.strftime('%Y-%m-%d %H:%M:%S')
print(nowDatetime)  # 2018-07-28 12:11:32

2020.06.02

Class member variable


A. dir
class Obj:
    def __init__(self):
        self.x = 9
obj=Obj()
print( dir(obj) )
>>> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'x']

B. __dict__
print(obj.__dict__)
>>> {'x': 9}


๋ณ€์ˆ˜ ์กด์žฌ ํ™•์ธ

  1. Try / Exception

try : 
     thevariable
exception NameError :
     print('The variablle wasn't defined'_
else :
     print('It is defined') 

  1. variable

if 'myVar' in locals(): # local variable ์ผ ๊ฒฝ์šฐ
if 'myVar' in globals(): # global variable ์ผ ๊ฒฝ์šฐ
if  hasattr(obj,'attr_name') : # obj name์ด ์กด์žฌํ•  ๊ฒฝ์šฐ

2020.06.08

AWS EC2 ubuntu ์œ ์ € ์ƒ์„ฑ(pem ํŒŒ์ผ์—†์ด ํŒจ์Šค์›Œ๋“œ ์‚ฌ์šฉ ์ ‘์†)

sudo useradd -s /bin/bash -m -d /home/mckam -g root USERNAME

sudo passwd USERNAME PASSWORD

sudo chmod u+w /etc/sudoers

sudo nano /etc/sudoers USERNAME ALL=(ALL:ALL) ALL

sudo nano /etc/ssh/sshd_config PasswordAuthentication yes

sudo service ssh restart

ssh USERNAME@IP ADRESS PASSWORD

2020.06.23

Pandas DataFrame ์ค‘๋ณต์ œ๊ฑฐ


df.drop_duplicates([A, B], keep='first') # A, B : ์ค‘๋ณต ์—ฌ๋ถ€ ๊ธฐ์ค€ Columns

Pandas DataFrame index ์ดˆ๊ธฐํ™”


df.reset_index(drop=True)

2020.06.27

๋ฆฌ์ŠคํŠธํ˜• ๋‚ด์—์„œ์˜ ์ž„์˜์˜ ์™ธ๋ถ€ ์ˆซ์ž ์œ„์น˜ ํ™•์ธ


A = [1,4,6,7]
num = 5

A.append(num)
A.sort()
pos = A.index(num)
A.remove(num)

2020.06.29

ํŒŒ์ผ ์‹คํ–‰


import os

os.startfile(filename)

2020.07.13

๊ตฌ๊ธ€์Šคํ”„๋ ˆ๋“œ์‹œํŠธ ์ฃผ์‹ ๋ฐ์ดํ„ฐ ๋ฐ›๊ธฐ

GOOGLEFINANCE

  • KOSPI ์ง€์ˆ˜ 10์ผ ๋ฐ์ดํ„ฐ =GOOGLEFINANCE("KRX:KOSPI", "price", Today()-10, Today(), "DAILY")
  • KOSDQ ์ง€์ˆ˜ 20์ผ ๋ฐ์ดํ„ฐ =GOOGLEFINANCE("KOSDAQ:KOSDAQ", "price", Today()-20, Today(), "DAILY")
  • KOSPI ์ข…๋ชฉ ํ˜„์žฌ๊ฐ€ =GOOGLEFINANCE("KRX:035720")
  • KOSDAQ ์ข…๋ชฉ ํ˜„์žฌ๊ฐ€ =GOOGLEFINANCE("KOSDAQ:258790")
  • NASDAQ ์ข…๋ชฉ ํ˜„์žฌ๊ฐ€ =GOOGLEFINANCE("NASDAQ:SBUX")
  • NYSE ์ข…๋ชฉ ํ˜„์žฌ๊ฐ€ =GOOGLEFINANCE("NYSE:DIS")

2020.07.14

SQLite3 ๋ฐ์ดํ„ฐ ์ค‘๋ณต ์ œ๊ฑฐ

  • "DELETE FROM ??? WHERE rowid NOT IN (SELECT Max(rowid) FROM ??? GROUP BY TITLE order by TITLE)"
  • "DELETE FROM Holiday WHERE rowid NOT IN (SELECT Max(rowid) FROM Holiday GROUP BY Holiday order by Holiday)"

2020.07.15

SQLite3 DataFrame ์ €์žฅ

  • df.to_sql('table', conn, if_exists='replace', index=False)

2020.07.16

SQLite3 query


select ์‹œ์žฅ๊ตฌ๋ถ„, ์ข…๋ชฉ์ฝ”๋“œ, ์ข…๋ชฉ๋ช…, ์ฃผ์‹์ˆ˜, ์ „์ผ์ข…๊ฐ€, ์ „์ผ์ข…๊ฐ€*์ฃผ์‹์ˆ˜ as ์‹œ๊ฐ€์ด์•ก  
            from ์ข…๋ชฉ์ฝ”๋“œ    
            order by ์‹œ์žฅ๊ตฌ๋ถ„, ์ข…๋ชฉ์ฝ”๋“œ  

2020.07.20

ํฌ๋กค๋ง requests SSLError ํ•ด๊ฒฐ

  • requests.get(url, verify=False)

2020.08.08

Pandas Sorting


df.sort_values(by="A", ascending=False) # ascending=False : ๋‚ด๋ฆผ์ฐจ์ˆœ
df.sort_values(['rank', 'rank1', 'rank2'], ascending=[True,True,True])

Pandas Rank


df['rank1'] = df['A'].rank(ascending=False)

2020.09.15

Pandas String to DateTime


df['col'] = pd.to_datetime(df['col'])
pd.to_datetime(pd.Series(['05/23/2005']))
pd.to_datetime(pd.Series(['05/23/2005']), format="%m/%d/%Y")

2020.09.25

SQLite3 query


query = """
    SELECT A.๋‚ ์งœ, A.๊ธฐ๊ฐ„๊ตฌ๋ถ„, A.์ข…๋ชฉ์ฝ”๋“œ, C.์ข…๋ชฉ๋ช…, B.์ข…๊ฐ€, A.๋งค์ถœ์•ก, A.์˜์—…์ด์ต, A.๋‹น๊ธฐ์ˆœ์ด์ต, A.์ž์‚ฐ์ด๊ณ„, A.๋ถ€์ฑ„์ด๊ณ„, A.์ž๋ณธ์ด๊ณ„, A.์ž๋ณธ๊ธˆ, 
        A.๋ถ€์ฑ„๋น„์œจ, A.์œ ๋ณด์œจ, A.์˜์—…์ด์ต๋ฅ , A.์ˆœ์ด์ต๋ฅ , A.ROA, A.ROE, A.EPS, A.BPS, A.DPS, A.PER, 1/A.PER as RPER, A.PBR, A.๋ฐœํ–‰์ฃผ์‹์ˆ˜, A.๋ฐฐ๋‹น์ˆ˜์ต๋ฅ , C.์ข…๋ชฉ์ƒํƒœ
    FROM ์žฌ๋ฌด์ •๋ณด A, (select ์ข…๋ชฉ์ฝ”๋“œ, ์ข…๊ฐ€ from ์ผ๋ณ„์ฃผ๊ฐ€ where ์ผ์ž = (select max(์ผ์ž) from ์ผ๋ณ„์ฃผ๊ฐ€ where ์ผ์ž <= '%s')) B, ์ข…๋ชฉ์ฝ”๋“œ_์ฃผ์‹ C
    WHERE ๋‚ ์งœ='%s' and ๊ธฐ๊ฐ„๊ตฌ๋ถ„='%s' and A.์ข…๋ชฉ์ฝ”๋“œ=B.์ข…๋ชฉ์ฝ”๋“œ and A.์ข…๋ชฉ์ฝ”๋“œ=C.์ข…๋ชฉ์ฝ”๋“œ
    """ % (๋‚ ์งœ, ๋‚ ์งœ, ๊ธฐ๊ฐ„๊ตฌ๋ถ„)

2020.09.30

R


library(boot)
data(nodal)
data(nodal)
a<-c(2,4,6,7)
data <- nodal[,a]
glmModel <- glm(r~., data=data, family = "binomial")
summary(glmModel)


Moving Averages
Calculate various moving averages (MA) of a series.
SMA(x, n = 10, ...)


์ฃผ์„ฑ๋ถ„๋ถ„์„ PCA(Principal Component Analysis)
college_s <- scale(college)
summary(college_s
fit <- princomp(college_s)
fit$loadings


# ์ตœ์ ํšŒ๊ท€_๋ณ€์ˆ˜์„ ํƒ๋ฒ•
step(lm(์ถœ๋ ฅ๋ณ€์ˆ˜~์ž…๋ ฅ๋ณ€์ˆ˜, ๋ฐ์ดํ„ฐ์„ธํŠธ), scope=list(lower=~1, upper=~์ž…๋ ฅ๋ณ€์ˆ˜), direction="๋ณ€์ˆ˜์„ ํƒ๋ฐฉ๋ฒ•")
# ์˜ˆ์ œ
step(lm(y~1, data=df), scope=list(lower=~1, upper=~x1+x2+x3+x4), direction="forward")

2020.10.05

R


# ์—ฐ๊ด€์„ฑ ๋ถ„์„ apriori(arules ํŒจํ‚ค์ง€)
> data(Groceries)
> inspect(Groceries[1:3])
> rules <- apriori(Froceries, parameter=list(support=0.01, confidence=0.3))
> inspect(sort(rules, by=c("lift"), decreasing=TRUE)[1:20])


# ๊ตฐ์ง‘๋ถ„์„(k-means)
> data(iris)
> newiris <- iris
> newiris$Species <- NULL
> kc <- kmeans(newiris, 3)
> table(iris$Species, kc$cluster)
> plot(newiris[c("Sepal.Length", "Sepal.Width")], col=kc$cluster)

2020.10.09

R


# reshape 
# 1. melt
> aqm = melt(airquality, id=c('month', 'day'), na.rm=TRUE)
# 2. cast
> a <- cast(aqm, day~month~variable)


# sqldf
> sqldf("select * from [data frame]")
> sqldf("select * from [data frame] limit 10")
> sqldf("select * from [data frame] where [col] like 'char%' ")

2020.10.10

R


# ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์กฐํšŒ 
# 1. data.frame์—์„œ ๋ฐ”๋กœ ์กฐํšŒ
> test[test$ํ•™๊ณผ=='๊ฒฝ์˜ํ•™๊ณผ',]
# 2. subset์œผ๋กœ ๋ฐ์ดํ„ฐ์…‹ ์กฐํšŒ
> subset(test, subset=(ํ•™๊ณผ=="๊ฒฝ์˜ํ•™๊ณผ"))

2020.10.15

R


# ๋ฐ˜๋ณต 
> rep(1,time=5)
> rep(1:4, each=2)
> rep(c, each=2
# ๋ฌธ์ž ๋ถ™์ด๊ธฐ
> A <- paste("a", "b", "c", sep="-")
> paste(A, c("e", "f"))
> paste(A, 10, sep="")
# ๋ฌธ์ž์—ด ์ถ”์ถœ
> substr("Bigdataanalysis",1,4) -> Bigd
# ๊ธฐ์ดˆ ํ†ต๊ณ„
> mean(๋ณ€์ˆ˜) # ํ‰๊ท 
> sum(๋ณ€์ˆ˜) # ํ•ฉ๊ณ„
> median(๋ณ€์ˆ˜) # ์ค‘์•™๊ฐ’
> sd(๋ณ€์ˆ˜) # ํ‘œ์ค€ํŽธ์ฐจ
> var(๋ณ€์ˆ˜) # ๋ถ„์‚ฐ
> cov(๋ณ€์ˆ˜1, ๋ณ€์ˆ˜2) # ๊ณต๋ถ„์‚ฐ
> cor(๋ณ€์ˆ˜1, ๋ณ€์ˆ˜2) # ์ƒ๊ด€๊ณ„์ˆ˜
# ํŒŒ์ผ ์ฝ๊ธฐ
> read.table("ํŒŒ์ผ์ด๋ฆ„", sep='๊ตฌ๋ถ„์ž')
> read.csv("ํŒŒ์ผ์ด๋ฆ„", header=T)

2020.10.21

R


# ๋ฌธ์ž์—ด ๊ธธ์ด
> nchar("๋ฌธ์ž์—ด")
# ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ
> paste("๋‹จ์–ด1", "๋‹จ์–ด2", sep='-')
> paste("the pi is approximately", pi)
# ํ•˜์œ„๋ฌธ์ž์—ด ์ถ”์ถœ
> substr("statistics", 1, 4)
# ๋‚ ์งœ ์กฐํšŒ
> format(Sys.Data(), '%a') # ์š”์ผ์กฐํšŒ
> format(Sys.Data(), '%b') # ์ถ•์•ฝ๋œ ์›”์ด๋ฆ„์กฐํšŒ
> format(Sys.Data(), '%B') # ์ „์ฒด ์›”์ด๋ฆ„์กฐํšŒ
> format(Sys.Data(), '%d') # ๋‘์ž๋ฆฌ ์ˆซ์ž์˜ ์ผ์กฐํšŒ
> format(Sys.Data(), '%m') # ๋‘์ž๋ฆฌ ์ˆซ์ž์˜ ์›”์กฐํšŒ
> format(Sys.Data(), '%y') # ๋‘์ž๋ฆฌ ์ˆซ์ž์˜ ์—ฐ๋„์กฐํšŒ
> format(Sys.Data(), '%Y') # ๋„ค์ž๋ฆฌ ์ˆซ์ž์˜ ์—ฐ๋„์กฐํšŒ
# ๋‚ ์งœ ์ถ”์ถœ
> d <- as.Date("2014-12-25")
> start <- as.Date("2014-12-01")
> end <- as.Date("2014-12-25")
> seq(from=start, to=end, by=1)

2020.10.26

R


# ์ƒ๊ด€๋ถ„์„
# ๋ถ„์‚ฐ
> var(x, y=NULL, na.rm=FALSE)
# ๊ณต๋ถ„์‚ฐ
> cov(x, y=NULL, use='everything', method=c('pearson', 'kendall', 'spearman'))
# ์ƒ๊ด€๊ด€๊ณ„
> cor(x, y=NULL, use='everything', method=c('pearson', 'kendall', 'spearman'))
> rcorr(matrix(data๋ช…), type=c('pearson', 'kendall', 'spearman'))

2020.10.28

R


# R ๊ธฐ์ดˆ ๋ฌธ์ œ
# 1
> x <- 1:100
> sum(x>50)

# 2
> x <- c(1,2,3,NA)
> mean(x)

# 3
> s <- c("Monday", "Tuesday", "Wednesday")
> substr(s, 1, 2)

# 4
> c(2,4,6,8) + c(1,3,5,7,9)

# 5
> set.seed(1000)
> sample(1:1000, 50)

# 6 ์ž˜๋ชป๋œ ๊ฒƒ ์ฐพ๊ธฐ
> x<-c(1:4)
> y<-c("apple","banana","orange")
> xy<-x(x,y)
## A. xy๋Š” ๋ฌธ์žํ˜• ๋ฒกํ„ฐ
## B. xy์˜ ๊ธธ์ด๋Š” 7
## C. xy[1] + xy[2]์˜ ๊ฒฐ๊ณผ๋Š” 3
## D. xy[5:7]์€ y์™€ ๋™์ผ

# 7 ๋‹ค๋ฅธ ๊ฒฐ๊ณผ ์ฐพ๊ธฐ
> A <- cbind(c(1,2,3), c(4,5,6), c(7,8,9))
> colnames(A) <- c("A","B","C")
> rownames(A) <- c("r1","r2","r3")
## A[,"A"}
## A[-c(2,3),]
## A[,1]
## A[, -(2:3)]

# SQL ๊ธฐ์ดˆ ๋ฌธ์ œ
# 1. ( )๋Š”?
SELECT NAME, GENDER, SALARY
FROM CUSTOMERS
WHERE AGE (   ) 20 AND 30

# 2. ํ•ด๋‹น SQL๋ฌธ ๋ถ„์„
select customer_name, ๊ณ ๊ฐ๋ช…, e_customer_name, ๊ณ ๊ฐ ์˜๋ฌธ๋ช…
from customer
where e_customer_name like '_A%';

# 3. xy์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ๋ถ€์ ์ ˆํ•œ ๊ฒƒ์€?
> x <- c(1:5)
> y <- seq(10,50,10)
> xy <- rbind(x,y)
- 1. 2x5 ํ–‰๋ ฌ์ด๋‹ค.
- 2. xy[1,]์€ x์™€ ๋™์ผํ•˜๋‹ค.
- 3. xy[,1]์€ y์™€ ๋™์ผํ•˜๋‹ค.
- 4. Matrix ํƒ€์ž…์˜ ๊ฐœ์ฒด์ด๋‹ค.

R reshape

melt

melt(MYDATA, id=c("no", "day"))

cast

cast(MD, no+variableday) cast(MD, novariable, mean) cast(MD, no-variable+day)

2020.11.13

Python openpyxl

1. ์—‘์…€ ํŒŒ์ผ ์ƒ์„ฑ

 
from openpyxl import Workbook

# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์ €์žฅ
wb.save(fileName)

2. ๊ฐ’ ์ž…๋ ฅ

 
from openpyxl import Workbook
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# ์ฒซ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws['A1'] = 1
 
# ๋‘๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws.cell(2,1,'B') # ws.cell(row=2, column=1, value=2)
 
# ์„ธ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws.append([2,'',4])
 
# ๋„ค๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
for rng in ws['E1':'F3']:
    for cell in rng:
        cell.value = 'Hello'
 
# ๋‹ค์„ฏ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
for r in range(4,7):
    ws.cell(r,1,'World') # [A4:A6]
 
# ์ €์žฅ
wb.save(fileName)

3. ๊ฐ’ ์ถœ๋ ฅ

 
from openpyxl import Workbook
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# ์ฒซ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws['A1'] = 1
 
# ๋‘๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws.cell(2,1,'B') # ws.cell(row=2, column=1, value=2)
 
# ์„ธ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
ws.append([2,'',4])
 
# ๋„ค๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
for rng in ws['E1':'F3']:
    for cell in rng:
        cell.value = 'Hello'
 
# ๋‹ค์„ฏ๋ฒˆ์งธ ์ž…๋ ฅ๋ฐฉ๋ฒ•
for r in range(4,7):
    ws.cell(r,1,'World') # [A4:A6]
 
# ์ฒซ๋ฒˆ์งธ ์ถœ๋ ฅ๋ฐฉ๋ฒ•
print(ws['A1'])
 
# ๋‘๋ฒˆ์งธ ์ถœ๋ ฅ๋ฐฉ๋ฒ•
print(ws.cell(2,1).value)
 
# ์„ธ๋ฒˆ์งธ ์ถœ๋ ฅ๋ฐฉ๋ฒ•
for rng in ws['E1':'F3']:
    for cell in rng:
        print(cell.value)
 
# ๋„ค๋ฒˆ์งธ ์ถœ๋ ฅ๋ฐฉ๋ฒ•
for r in range(4,7):
    print(ws.cell(r,1).value) # [A4:A6]
 
# ์ €์žฅ
wb.save(fileName)

4. ํ•จ์ˆ˜ ์ž…๋ ฅ

 
from openpyxl import Workbook
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
ws['A1'] = 10
ws['A2'] = 20
ws['A3'] = 30
ws['A4'] = 40
ws['A5'] = '=SUM(A1:A4)' # ํ•ฉ๊ณ„ ํ•จ์ˆ˜
 
# ์ €์žฅ
wb.save(fileName)

5. ์…€ ์„œ์‹

 
from openpyxl import Workbook
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# A1 ์ž…๋ ฅ + ํ˜•์‹๋ณ€๊ฒฝ
ws['A1'] = 1000
ws['A1'].number_format = '#,##0'
 
# A2 ์ž…๋ ฅ + ํ˜•์‹๋ณ€๊ฒฝ
ws.cell(2,1,2000).number_format = '#,##0'
 
# B1, B2 ์ž…๋ ฅ + B์—ด ํ˜•์‹๋ณ€๊ฒฝ
ws['B1'] = 3000
ws['B2'] = 4000
for rng in ws['B:B']:
    rng.number_format = '#,##0'
 
# C1:D3 ์ž…๋ ฅ + ํ˜•์‹๋ณ€๊ฒฝ
for rng in ws['C1':'D3']:
    for cell in rng:
        cell.value = 5000
        cell.number_format = '#,##0'
 
# E1, E2, E3 ์ž…๋ ฅ + ํ˜•์‹๋ณ€๊ฒฝ
ws['E1'] = -250
ws['E2'] = 250
ws['E3'] = -300
ws['E4'] = 0
for rng in ws['E1':'E4']:
    for cell in rng:
        cell.number_format = '[RED]#,##0;[BLUE]-#,##0;"-"' # ์–‘์ˆ˜๋ฉด ๋นจ๊ฐ• ์Œ์ˆ˜๋ฉด ํŒŒ๋ž‘ 0์ด๋ฉด -
 
# ์ €์žฅ
wb.save(fileName)

6. ์…€ ๋ณ‘ํ•ฉ

 
from openpyxl import Workbook
from openpyxl.styles import Alignment
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# A1:C1 ๋ณ‘ํ•ฉ
ws.merge_cells('A1:C1')
 
# ๊ฐ€์šด๋ฐ๋งž์ถค
ws['A1'].alignment = Alignment('center', 'center') # Alignment(horizontal='center', vertical='center') 
 
# A1 ์ž…๋ ฅ
ws['A1'] = 'Hello World !'
 
# A1:C1 ๋ณ‘ํ•ฉ ํ•ด์ œ
# ws.unmerge_cells('A1:C1')
 
# ์ €์žฅ
wb.save(fileName)

7. ๋งˆ์ง€๋ง‰ ํ–‰, ์—ด ๋ฒˆํ˜ธ

 
from openpyxl import Workbook
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# ๋งˆ์ง€๋ง‰ ํ–‰ ๊ตฌํ•˜๊ธฐ
print('์ž…๋ ฅ ์ „: ' + str(ws.max_row))
 
# [A1:A10] ์ž…๋ ฅ
for rng in ws['A1:A10']:
    for cell in rng:
        cell.value = 'Excel'
 
# ๋งˆ์ง€๋ง‰ ํ–‰ ๊ตฌํ•˜๊ธฐ
print('์ž…๋ ฅ ํ›„: ' + str(ws.max_row))
 
# ๋งˆ์ง€๋ง‰ ์—ด ๊ตฌํ•˜๊ธฐ
print('์ž…๋ ฅ ์ „: ' + str(ws.max_column))
 
# [B1:G1] ์ž…๋ ฅ
for rng in ws['B1:G1']:
    for cell in rng:
        cell.value = 'Python'
 
# ๋งˆ์ง€๋ง‰ ํ–‰ ๊ตฌํ•˜๊ธฐ
print('์ž…๋ ฅ ํ›„: ' + str(ws.max_column))
 
# ์ž…๋ ฅ ๋œ ์—ด ๊ตฌํ•˜๊ธฐ
for cell in ws['1:1'].__iter__():
    print(cell.value)
 
# ์ €์žฅ
wb.save(fileName)

8. ํ…Œ๋‘๋ฆฌ

 
from openpyxl.styles import Border, Side
from openpyxl import Workbook, styles
 
# ํŒŒ์ผ๋ช…
 
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์›Œํฌ๋ถ ํ™œ์„ฑํ™”
ws = wb.active
 
# B2 ์ž…๋ ฅ
ws['B2'] = 'Hello'
# ์™ผ์ชฝ ํ…Œ๋‘๋ฆฌ
ws['B2'].border = Border(left=Side(style='thin'))
# B3 ์ž…๋ ฅ
ws['B4'] = 'Excel'
# ์™ผ์ชฝ ํ…Œ๋‘๋ฆฌ
ws['B4'].border = Border(Side('thin'))
 
# D2 ์ž…๋ ฅ
ws['D2'] = 'Hello'
# ์˜ค๋ฅธ์ชฝ ํ…Œ๋‘๋ฆฌ
ws['D2'].border = Border(right=Side(style='thin'))
# D4 ์ž…๋ ฅ
ws['D4'] = 'Excel'
# ์˜ค๋ฅธ์ชฝ ํ…Œ๋‘๋ฆฌ
ws['D4'].border = Border(None, Side('thin'))
 
# F2 ์ž…๋ ฅ
ws['F2'] = 'python'
# ๋ชจ๋“  ํ…Œ๋‘๋ฆฌ
ws['F2'].border = Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),bottom=Side(style='thin'))
# F4 ์ž…๋ ฅ
ws['F4'] = 'python'
# ๋ชจ๋“  ํ…Œ๋‘๋ฆฌ
ws['F4'].border = Border(Side('thin'),Side('thin'),Side('thin'),Side('thin'))
 
# ์‚ฌ์šฉ์ž ์Šคํƒ€์ผ
THIN_BORDER = Border(Side('thin'),Side('thin'),Side('thin'),Side('thin'))
# H2 ์ž…๋ ฅ
ws['H2'] = 'Style'
# ๋ชจ๋“  ํ…Œ๋‘๋ฆฌ
ws['H2'].border = THIN_BORDER
# H4 ์ž…๋ ฅ
ws['H4'] = 'Style'
# ๋ชจ๋“  ํ…Œ๋‘๋ฆฌ
ws['H4'].border = THIN_BORDER
 
# ๋ฒ”์œ„ ํ…Œ๋‘๋ฆฌ ์„ค์ •
for rng in ws['J2:K10']:
    for cell in rng:
        cell.value = 'All' # [J2:K10] = 'All'
        cell.border = THIN_BORDER # [J2:K10] ๋ชจ๋“ ํ…Œ๋‘๋ฆฌ ์„ค์ •
 
# ์ €์žฅ
wb.save(fileName)

9. ์‹œํŠธ

 
from openpyxl.styles import Border, Side
from openpyxl import Workbook, styles
 
# ํŒŒ์ผ๋ช…
fileName = 'TEST.xlsx'
 
# ์›Œํฌ๋ถ ์ƒ์„ฑ
wb = Workbook()
 
# ์‹œํŠธ1 ์ƒ์„ฑ
ws_1 = wb.create_sheet()
 
# ์‹œํŠธ2 ์ƒ์„ฑ
ws_2 = wb.create_sheet()

# ์‹œํŠธ2 ์‹œํŠธ๋ช… ๋ณ€๊ฒฝ
ws_2.title = '์‹œํŠธ2'
 
# ์‹œํŠธ3 ์ƒ์„ฑ (์‹œํŠธ๋ช… ์ •์˜)
ws_3 = wb.create_sheet('์‹œํŠธ3')
 
# ์‹œํŠธ๋ช… ์ถœ๋ ฅ
for sheetName in wb.sheetnames:
    print(sheetName)
 
# ๋ชจ๋“  ์›Œํฌ์‹œํŠธ A1 ์ž…๋ ฅ
for wss in wb.worksheets:
    wss['A1'] = 'python'
 
# ํŠน์ • ์›Œํฌ์‹œํŠธ A2 ์ž…๋ ฅ
ws = wb.get_sheet_by_name('์‹œํŠธ3')
ws['A2'] = 'hello'
 
# ์ €์žฅ
wb.save(fileName)

10. Excel to Text

 
import openpyxl

def find_parks_not_in_us():
    # ์—‘์…€ํŒŒ์ผ(์›Œํฌ๋ถ) ์—ด๊ธฐ
    wb = openpyxl.load_workbook('example.xlsx')
    
    # ์›Œํฌ์‹œํŠธ ์—ด๊ธฐ
    sheet = wb.get_sheet_by_name('Sheet1')
    
    # ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ
    parklist = []
    
    # ํŒŒ์ผ์„ ๋กœ์šฐ ๋‹จ์œ„๋กœ ์ฝ์–ด ๊ตญ๊ฐ€๊ฐ€ US๊ฐ€ ์•„๋‹Œ ๋กœ์šฐ๋ฅผ ํŒŒ์ผ๋กœ ์“ด๋‹ค.
    # 1. ํŒŒ์ผ์„ ์ฝ์„ ๋ฒ”์œ„๋ฅผ ๊ฒฐ์ •
    # 2. ๋กœ์šฐ๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ US๊ฐ€ ์•„๋‹Œ ๋กœ์šฐ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ ๋‹ค.
    for row in sheet[2:sheet.max_row]:
        print(row)
        if row[5].value != 'US':
            parklist.append(row)
    wb.close()
    return parklist
    
def make_file(partlist):
    with open('parklist.txt', 'w', encoding='utf-8') as file:
        for item in parklist:
            part_str = make_parkstr(item)
            file.write(park_str + '\n')
            
def make_parkstr(t):
    result_str = ''
    
    for item in t:
        result_str += str(item.value) + '\t'
        
    return result_str
    
def main():
    parklist = find_parks_not_in_us()
    make_file(parklist)
    print('parklist.txt ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.')
    
if __name__ == '__main__':
    main()

2021.01.10

Python ๊ฐ€์ƒํ™˜๊ฒฝ Batch ํŒŒ์ผ ์‹คํ–‰


call conda activate [env_name] 
call cd [path] 
call python [file_name.py]

2021.01.13

Pandas DataFrame ๊ทธ๋ฆผํŒŒ์ผ๋กœ ๋ณ€ํ™˜


import dataframe_image as dfi

dfi.export(df, 'result.png')

2021.01.16

R


# ์ฐจํ•จ์ˆ˜
> x <- c(1,2,4,5,7,9,10)
> y <- c(1,2,3,4,5,8,10)
> z <- setdiff(x, y)
7 9
> z <- setdiff(y, x)
3 8
# ๊ต์ง‘ํ•ฉ
> z <- intersect(x, y)
1 2 4 5 10

2021.03.25

ํŒŒ์ด์ฌ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ cython์„ ํ™œ์šฉ

  1. ๋‹ค๋ฅธ py์—์„œ importํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ชจ๋“ˆํ™” ํ•˜์—ฌ py ์ž‘์„ฑ
  2. ํ™•์žฅ์ž๋ฅผ pyx๋กœ ๋ณ€๊ฒฝ
  3. setup.py ์ƒ์„ฑ

    from distutils.core import setup
    from Cython.Build import cythonize
    setup(ext_modules = cythonize('pyxํŒŒ์ผ๋ช…'))    

  1. cmd์ฐฝ์—์„œ python setup.py build_ext --inplace
  2. ์‹คํ–‰์šฉ py ์ƒ์„ฑํ•˜์—ฌ import ํŒŒ์ผ๋ช…
    <GUI ๋ฒ„์ ผ์ผ ๊ฒฝ์šฐ ์˜ˆ์‹œ>

    import PowerControl as pc
    app = pc.QApplication(pc.sys.argv)
    myWindow = pc.MyWindow()
    app.exec()

  1. ๋ฐฐํฌ ์‹œ ์‹คํ–‰์šฉ py, pyd(pydํŒŒ์ผ๋ช…์— py37~~ ์‚ญ์ œ ๊ฐ€๋Šฅ), uiํŒŒ์ผ(GUI๋ฒ„์ ผ์ผ ๊ฒฝ์šฐ)

About

Today I learned

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published