- 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
- git config --global core.editor "nano"
- git reset --hard commit-ID
- git reset --soft commit-ID
- git log --all --grape -- oneline
- git commit --amend
- git init
- git remote add origin "http adress"
- git pull origin master
- git add *
- git commit -m "Message"
- git push --set-upstream origin master
import py_compile
py_compile.compile('py file name')
C:\Anaconda3\python.exe pyc_compile.py
C:\Anaconda3\envs\python36\python.exe pyc_compile.py
- ValueError: If using all scalar values, you must pass an index
- ์ฐธ์กฐ
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}])
data = ["first", "second", "third"]
for name in data:
for i in range(1,4):
globals()[name] = [x*i for x in range(3)]
import json
with open('?????.json', 'w', encoding='utf-8') as make_file:
json.dump(json_data, make_file, indent="\t")
import json
with open('?????.json', 'r') as f:
admin_info = json.load(f)
print(admin_info)
import os
admin_info_file = os.getenv('NAME')
>>> 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]])
cmd / powershell ๊ด๋ฆฌ์๋ชจ๋๋ก ์คํ
ssh -i "AWSKEY.pem" ubuntu@ec2-IP์ฃผ์.ap-northeast-2.compute.amazonaws.com
- python3 application.py : ํ์ด์ฌ ์๋ฒ ๊ตฌ๋
- Ctrl + Z : ํ๋ก์ธ์ค ์ค์ง
- bg : ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ฒ ๋ค์ ๊ตฌ๋
- disown -h : ์์ ๊ถ ํฌ๊ธฐ
- netstat -nap | grep {ํฌํธ ๋ฒํธ}: ํน์ ํฌํธ ๋ฒํธ์์ ๋์๊ฐ๋ ํ๋ก์ธ์ค๋ฅผ ํ์ธํ๊ธฐ
- kill -9 {ํ๋ก์ธ์ค ๋ฒํธ}: ํน์ ํ ํ๋ก์ธ์ค๋ฅผ ์ข ๋ฃ์ํค๊ธฐ
- jobs : ํ๋ก์ธ์ค ํ์ธ
- fg : ํฌ์ด๊ทธ๋ผ์ด๋
- ssh [email protected]
- PASSWORD
- python3 application.py
- Ctrl + Z
- bg
- disown -h
- 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
- set CONDA_FORCE_32BIT=1
- conda create -n XXXXXXX python=3.7 anaconda
- conda activate XXXXXXX
- conda deactivate
# ๊ณต๋ฐฑ ์ ๊ฑฐ
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@.]') # ์
๋ ฅํจํด๊ณผ ์ผ์น ์ฌ๋ถ
# ํ์ผ ๋ชฉ๋ก ์ป๊ธฐ
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) # ํ์ฅ์์ ๋๋จธ์ง ๋ถ๋ฆฌ
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
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}
- Try / Exception
try :
thevariable
exception NameError :
print('The variablle wasn't defined'_
else :
print('It is defined')
- variable
if 'myVar' in locals(): # local variable ์ผ ๊ฒฝ์ฐ
if 'myVar' in globals(): # global variable ์ผ ๊ฒฝ์ฐ
if hasattr(obj,'attr_name') : # obj name์ด ์กด์ฌํ ๊ฒฝ์ฐ
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
df.drop_duplicates([A, B], keep='first') # A, B : ์ค๋ณต ์ฌ๋ถ ๊ธฐ์ค Columns
df.reset_index(drop=True)
A = [1,4,6,7]
num = 5
A.append(num)
A.sort()
pos = A.index(num)
A.remove(num)
import os
os.startfile(filename)
- 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")
- "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)"
- df.to_sql('table', conn, if_exists='replace', index=False)
select ์์ฅ๊ตฌ๋ถ, ์ข
๋ชฉ์ฝ๋, ์ข
๋ชฉ๋ช
, ์ฃผ์์, ์ ์ผ์ข
๊ฐ, ์ ์ผ์ข
๊ฐ*์ฃผ์์ as ์๊ฐ์ด์ก
from ์ข
๋ชฉ์ฝ๋
order by ์์ฅ๊ตฌ๋ถ, ์ข
๋ชฉ์ฝ๋
- requests.get(url, verify=False)
df.sort_values(by="A", ascending=False) # ascending=False : ๋ด๋ฆผ์ฐจ์
df.sort_values(['rank', 'rank1', 'rank2'], ascending=[True,True,True])
df['rank1'] = df['A'].rank(ascending=False)
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")
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.์ข
๋ชฉ์ฝ๋
""" % (๋ ์ง, ๋ ์ง, ๊ธฐ๊ฐ๊ตฌ๋ถ)
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")
# ์ฐ๊ด์ฑ ๋ถ์ 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)
# 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%' ")
# ๋ฐ์ดํฐํ๋ ์ ์กฐํ
# 1. data.frame์์ ๋ฐ๋ก ์กฐํ
> test[test$ํ๊ณผ=='๊ฒฝ์ํ๊ณผ',]
# 2. subset์ผ๋ก ๋ฐ์ดํฐ์
์กฐํ
> subset(test, subset=(ํ๊ณผ=="๊ฒฝ์ํ๊ณผ"))
# ๋ฐ๋ณต
> 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)
# ๋ฌธ์์ด ๊ธธ์ด
> 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)
# ์๊ด๋ถ์
# ๋ถ์ฐ
> 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'))
# 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 ํ์
์ ๊ฐ์ฒด์ด๋ค.
melt(MYDATA, id=c("no", "day"))
cast(MD, no+variableday)
cast(MD, novariable, mean)
cast(MD, no-variable+day)
from openpyxl import Workbook
# ํ์ผ๋ช
fileName = 'TEST.xlsx'
# ์ํฌ๋ถ ์์ฑ
wb = Workbook()
# ์ ์ฅ
wb.save(fileName)
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)
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)
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)
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)
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)
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)
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)
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)
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()
call conda activate [env_name]
call cd [path]
call python [file_name.py]
import dataframe_image as dfi
dfi.export(df, 'result.png')
# ์ฐจํจ์
> 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
- ๋ค๋ฅธ py์์ importํด์ ์ฌ์ฉํ ์ ์๋๋ก ๋ชจ๋ํ ํ์ฌ py ์์ฑ
- ํ์ฅ์๋ฅผ pyx๋ก ๋ณ๊ฒฝ
- setup.py ์์ฑ
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('pyxํ์ผ๋ช
'))
- cmd์ฐฝ์์ python setup.py build_ext --inplace
- ์คํ์ฉ py ์์ฑํ์ฌ import ํ์ผ๋ช
<GUI ๋ฒ์ ผ์ผ ๊ฒฝ์ฐ ์์>
import PowerControl as pc
app = pc.QApplication(pc.sys.argv)
myWindow = pc.MyWindow()
app.exec()
- ๋ฐฐํฌ ์ ์คํ์ฉ py, pyd(pydํ์ผ๋ช ์ py37~~ ์ญ์ ๊ฐ๋ฅ), uiํ์ผ(GUI๋ฒ์ ผ์ผ ๊ฒฝ์ฐ)