程式包
python程式包下載地址:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
也可通過pip命令安裝
機器學習相關包:Pandas、NumPy、 SciPy、sklearn
繪圖包:matplotlib
pandas學習網址
http://pandas.pydata.org/pandas-docs/stable/
sklearn學習網址:
http://scikit-learn.org/stable/
使用過程遇到的問題
讀檔案錯誤
OSError: Initializing from file failed
python讀檔案預設不支援中文
字串轉時間格式
data['time']=pd.to_datetime(data['time'],format='%Y-%m-%d %H:%M:%S')
資料中存在空值
ValueError: Input contains NaN, infinity or a value too large fordtype('float32')
判斷是否為空白
np.isnan(mat.any()) #and gets False
np.isfinite(mat.all()) #and gets True
去除空值
_train_data.dropna(inplace=True)# drop含有NA的行
填充上一個值
data_tmp.fillna(method=’pad’, inplace=True)#method按需修改
dataframe轉list
df.values.tolist()
dataframe中字串分割並轉成數值型計算
data.col1 = data.col2.apply(lambda x:std([float(item) for item in x.split(‘:’)]))
Windows下讀檔案pandas.read_csv(path)報錯:
OSError: Initializing from file failed
原因python3.6預設的是‘uft-8’編碼,改到window編碼即可。
sys._enablelegacywindowsfsencoding()
查看編碼
sys.getfilesystemencoding()