Skip to content

Instantly share code, notes, and snippets.

View yaojenkuo's full-sized avatar

Yao-Jen Kuo yaojenkuo

View GitHub Profile
@yaojenkuo
yaojenkuo / export_table_from_sqlite_import_to_mysql.py
Created June 30, 2022 06:28
Export table from SQLite and import to MySQL.
from sqlalchemy import create_engine
from urllib.parse import quote
import sqlite3
import pandas as pd
password = "YOURPASSWORD"
db_name = "YOURDBNAME"
table_name = "YOURTABLENAME"
connection_url = "mysql+pymysql://root:{0}@localhost:3306/{1}".format(quote(password), db_name)
engine = create_engine(connection_url)

約維安計畫:第二週

初嘗命令列的滋味。

基礎命令一覽

首先,我們將這篇文章會介紹的基礎命令全數列出:

pwd # print working directory
(base)~$ conda install mamba -n base -c conda-forge
(base)~$ source activate xeus-sql
(xeus-sql)~$ mamba install xeus-sql jupyterlab -c conda-forge
(xeus-sql)~$ jupyter notebook
(base)~$ R
> install.packages('IRkernel')
> IRkernel::installspec(user = FALSE)
> q()
(base)~$ conda install jupyter
(base)~$ jupyter --version
pwd # print working directory
mkdir folder_name # make directory
ls # list directory and file
cd folder_name # changing directory
touch file_name # create file
mv file_name file_name # move file
cp file_name file_name # copy file
rm file_name file_name # remove file
clear # clear command line, ctrl-L
# up-arrow / down-arrow for history commands
import pandas as pd
from urllib.parse import quote_plus
from string import ascii_uppercase
import re
class TaiwanElection2020:
def __init__(self):
self._counties = ['宜蘭縣', '彰化縣', '金門縣', '桃園市', '苗栗縣', '臺南市', '雲林縣', '南投縣', '高雄市', '臺北市', '新北市', '花蓮縣', '新竹市', '新竹縣', '基隆市', '連江縣', '嘉義縣', '嘉義市', '屏東縣', '澎湖縣', '臺東縣', '臺中市']
def tidy_dataframe(self, df):
# updating columns attributes
@yaojenkuo
yaojenkuo / a-try-except-demo.py
Created October 26, 2020 02:19
A try-except demo in class on 2020-10-26.
import pandas as pd
import datetime as dt
today = dt.date.today()
day_delta = dt.timedelta(1)
while True:
try:
today_str = today.strftime('%m-%d-%Y')
print("嘗試載入 {} 的資料...".format(today_str))
csv_url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/{}.csv'.format(today_str)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yaojenkuo
yaojenkuo / get_actual_historic_prices.R
Created September 2, 2020 10:23
Getting actual historic prices for split stock.
get_actual_historic_prices <- function(adjusted_prices, split_date_periods, split_ratios) {
n_splits <- length(split_ratios)
#xts_list <- list()
actual_historic_prices <- adjusted_prices[split_date_periods[n_splits + 1]]
for (i in n_splits:1) {
single_xts <- adjusted_prices[split_date_periods[[i]]] / prod(split_ratios[n_splits:i])
#actual_historic_prices <- rbind.xts(actual_historic_prices, single_xts)
actual_historic_prices <- rbind.xts(actual_historic_prices, single_xts)
}
return(actual_historic_prices)