亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決pandas使用read_csv()讀取文件遇到的問(wèn)題

 更新時(shí)間:2018年06月15日 08:40:36   作者:Zhang_Zhi_Qiang_1  
今天小編就為大家分享一篇解決pandas使用read_csv()讀取文件遇到的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

如下:

數(shù)據(jù)文件:

上海機(jī)場(chǎng) (sh600009)
24.11 3.58
東風(fēng)汽車 (sh600006) 74.25 1.74
中國(guó)國(guó)貿(mào) (sh600007) 26.38 2.66
包鋼股份 (sh600010) 61.01 2.35
武鋼股份 (sh600005) 75.85 1.3
浦發(fā)銀行 (sh600000) 6.65 0.96

在使用read_csv() API讀取CSV文件時(shí)求取某一列數(shù)據(jù)比較大小時(shí),

df=pd.read_csv(output_file,encoding='gb2312',names=['a','b','c'])
df.b>20

報(bào)錯(cuò)

TypeError:'>'not supported between instances of 'str' and 'int'

從返回的錯(cuò)誤信息可知應(yīng)該是數(shù)據(jù)類型錯(cuò)誤,讀回來(lái)的是‘str'

in : df.dtypes
out:
 a object
 b object
 c object
 dtype: object

由此可知 df.b 類型是 object

查閱read_csv()文檔 配置:

dtype : Type name or dict of column -> type, default None
Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32} (unsupported with engine='python'). Use str or object to preserve and not interpret dtype.

New in version 0.20.0: support for the Python parser.

可知默認(rèn)使用‘str'或‘object'保存

因此在讀取時(shí)只需要修改 'dtype' 配置就可以

df=pd.read_csv(output_file,encoding='gb2312',names=['a','b','c'],dtype={'b':np.folat64})

以上這篇解決pandas使用read_csv()讀取文件遇到的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論