Python
|
-|-
python|
w3cschool|
菜鸟教程|
Python123|
中国大学MOOC|
Python3 正则表达式_w3cschool|
API reference — pandas 0.25.1 documentation|
|
-|-
os.listdir([path])|
os.mkdir(path)|
os.system(string)|
os.path.exists(path)|
|
-|-
pathlib.Path(path).is_file()|
pathlib.Path(path).is_dir()|
pathlib.Path(path).exists()|
|
-|-
shutil.copyfile(src_path, des_path)|
|
-|-
re.match(pattern, string)|
re.search(pattern, string)|
re.sub(pattern, s, string)|
|
-|-
random.choice(list)|
random.shuffle(list)|
|
-|-
time.ctime()|
datetime.datetime.now().strftime('%a-%H%M%S-%y%m%d')|
检测文档的编码格式
import chardet
chardet.detect(open('0.csv', 'rb').read())['encoding']
将文件转成utf-8
def getEncoding(file_name):
with open(file_name, 'rb') as f:
return chardet.detect(f.read())['encoding']
def file2utf8(file_name):
with open(file_name, 'r', encoding = getEncoding(file_name)) as f:
s = f.read()
with open(file_name, 'w', encoding = 'utf-8') as f:
f.write(s)
pandas 读写文件
|
-|-
conda install xlrd xlwt|
import pandas as pd
import sqlite3 as sql
# Excel 转 数据库
pd.read_excel('age.xls').to_sql(con = sql.connect('age.db'), name='age', index=False)
# 数据库 转 Excel
pd.read_sql('select * from company', con = sql.connect('company.db')).to_excel('company.xls', index=False)
# Excel to csv
pd.read_excel('word.xls').to_csv('word.csv', index=False)
# csv to Excel
pd.read_csv('word.csv').to_excel('word.xls', index=False)

浙公网安备 33010602011771号