第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在 Python Pandas 數(shù)據(jù)類型 float64 上出現(xiàn)錯誤?

為什么在 Python Pandas 數(shù)據(jù)類型 float64 上出現(xiàn)錯誤?

開滿天機(jī) 2023-10-31 15:46:18
我使用 Windows PC 上的 jupyter 筆記本。我讀了一個數(shù)據(jù)幀,我調(diào)用 tran 如下tran = pd.read_csv("https://raw.githubusercontent.com/m1ngle/TRCount/main/TRCountUS.csv")當(dāng)我查看整個數(shù)據(jù)框的數(shù)據(jù)類型時,它效果很好tran.dtypesFIPS             int64State           objectYMTF             int64MTFPer         float64YFTM             int64FTMPer         float64YNB              int64NBPer          float64YTR              int64YTRper         float64NoTR             int64NoTRPer        float64DK               int64DKPer          float64DNAns            int64DNAPer         float64TotSurveyed      int64StatePop         int64TRPop            int64dtype: object當(dāng)我嘗試調(diào)用或使用任何 float64 列時,我收到錯誤tran['MTFPer'].dtypeKeyError                                  Traceback (most recent call last)~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)   2645             try:-> 2646                 return self._engine.get_loc(key)   2647             except KeyError:pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()KeyError: 'MTFPer'During handling of the above exception, another exception occurred:KeyError                                  Traceback (most recent call last)<ipython-input-85-2bd9c012f223> in <module>----> 1 tran['MTFPer'].dtype~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)   2798             if self.columns.nlevels > 1:   2799                 return self._getitem_multilevel(key)-> 2800             indexer = self.columns.get_loc(key)   2801             if is_integer(indexer):   2802                 indexer = [indexer]當(dāng)我使用任何 int64 數(shù)據(jù)類型時,不會發(fā)生此錯誤。tran['YMTF'].dtypedtype('int64')誰能幫我嗎?
查看完整描述

1 回答

?
瀟湘沐

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個贊

在讀取.csv文件時,pandas 還會讀取列中的空白。當(dāng)我tran[' MTFPer '].dtype代替 時tran['MTFPer'].dtype,pandas 給了我正確的答案。
也許稍微清理一下數(shù)據(jù)本身,或者您可以像這樣清理列名:

tran.columns = [c.strip() for c in tran.columns]


查看完整回答
反對 回復(fù) 2023-10-31
  • 1 回答
  • 0 關(guān)注
  • 233 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號