python使用備忘(一)__python

來源:互聯網
上載者:User

程式包
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()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.