Function or Method
python 有很多不同 function,因此我想在這篇寫所有 funtion 我會用到。我指的 function 不是傳 function,而是一些 libary function
Math
Datetime 時間
time
程式跑的時間
如果計算程式袍多就可以用這方法
1 | import time |
datetime
今天日期
- date.today 取今天日期
python 有很多不同 function,因此我想在這篇寫所有 funtion 我會用到。我指的 function 不是傳 function,而是一些 libary function
如果計算程式袍多就可以用這方法
1 | import time |
今天我想分享我學的 pandas 筆記,我覺得對於分大數據很有幫助,他有點像 mysql。請先下載 module 或 package:pip install pandas`
可以去 github 找相關 csv 檔案,然後去 raw 檔案做連線
1 | import pandas as pd |
pandas 會回傳 DataFrame 格式。<class 'pandas.core.frame.DataFrame'>
下面是印出所有資料表內容。
1 | total_bill tip sex smoker day time size |
head(N)
: 是查前面 N 筆資料1 | import openpyxl |
1 | import openpyxl |
1 | import openpyxl |
output:
1 | ['Sheet1', 'Sheet2', 'Sheet'] |
這裡會包含以下內內容:
for
*
list (快速讀 list 不需要用到 for
loop)enumerate
方法list : list = ['A','B','C','D','E','F']
我們可以用以下方法:
for
loop1 | list= [1,2,3] |
output:
1 2 3
*
list: 不需要 for loop ,可以 unpack list今天分享如何搜尋字串裡面的 substring 或如果有檔案(log)想找相關字來做分析。
我的 string 是:
st="[20221013.162853.788442][info]:[[40;32m>>> DL- ingress traffic: 0.010799(Mbps), egress traffic: 0.087016(Mbps), ReTx: 0.000220(Mbps)[0m]"
我想抓出時間和TPUT的直,如:[20221013.162853.788442]
和 0.010799(Mbps)
同時要把 []
和 (Mbps)
移除,可以用下面方式:
1 | st="[20221013.162853.788442][info]:[[40;32m>>> DL- ingress traffic: 0.010799(Mbps), egress traffic: 0.087016(Mbps), ReTx: 0.000220(Mbps)[0m]" |
1 | dateStr = st.split('[', 1)[1].split(']')[0] |
output:
20221013.162853.788442
open syntax:
open( file, mode, encoding="utf-8")
mode 字串 | 說明 |
---|---|
r | Read only 讀取模式 ( 預設 ) |
r+ | Read and write |
w | Write only 寫入模式,檔案若存在,會清空內容再寫入 ; 若檔案不存在,則建立新檔開啟寫入 |
w+ | write+read |
a | Append only 附加模式,若檔案存在,則寫入內容 會附加至檔 案尾端 |
a+ | Append and Read (‘a+’) |
讀取方法 | 描述 |
---|---|
read( ) | 一次讀取檔案所有的內容,回傳為字串 |
readline( ) | 只讀取一行內容 |
readlines( ) | 將所有檔案內容,每行讀入回傳為串列 |
1 | fileObj = open("路徑檔名" , "r", encoding="utf-8") |
1 | fileObj = open("路徑檔名" , "w", encoding="utf-8") |
I am sharing some Code Test during my Interview, and also some practice Code example.
今天分享我一些Live Coding 面試問題,還有一些刷題的問題。
If we have a log.txt, as below, you need to and search specfic string, like cat.
1 | 1 cat |
1 | with open("log.txt", "r") as textfile: |
1 | d={} |
1 | function createCard(initName){ |
output
createCard { name: ‘Ma’ }
createCard { name: ‘Ma2’ }
createCard { name: ‘Ma3’ }
=>
In ES6 there is a new function called array function, which you can write shorter function.
Before ES6
function hello(){}
after ES6
let hello = function (){}
shorthand
let hello = () =>{}
Before ES6 (normal function)
ex: function hello(){}
.alias_pofile
Recommend use this file, will not destory .bashrc
file.
1 | cd ~ |
.bashrc
This method need to reboot to take effect
cd
: change directory to home ~
directorycd folder
: change to specific directory