今天培训备课时,做列联表时:
cross_table = pd.crosstab(accepts.bankruptcy_ind,accepts.bad_ind, margins=True)
提示错误:
AttributeError: 'DataFrame' object has no attribute
ttributeError Traceback (most recent call last) <ipython-input-62-6a7117b99310> in <module> ----> 1cross_table = pd.crosstab(accepts.bankruptcy_ind,accepts.bad_ind, margins=True) d:\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5177 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5178 return self[name] -> 5179return object.__getattribute__(self, name) 5180 5181 def __setattr__(self, name, value): AttributeError: 'DataFrame' object has no attribute 'bankruptcy_ind'
后来发现,所有的列都读不出来,网上说,表列名有空格,我查了一下,是没有的。
但是用accepts.head()
还能正常显示,晕。
<<<<<<< HEAD | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
application_id | account_number | bad_ind | vehicle_year | vehicle_make | bankruptcy_ind | tot_derog | tot_tr | age_oldest_tr | tot_open_tr | tot_rev_tr | tot_rev_debt | tot_rev_line | rev_util | fico_score | purch_price | msrp | down_pyt | loan_term | loan_amt | ltv | tot_income | veh_mileage | used_ind | weight |
2314049 | 11613 | 1 | 1998 | FORD | N | 7 | 9 | 64 | 2 | 1 | 506 | 500 | 101 | 650 | 17200 | 17350 | 0 | 36 | 17200 | 99 | 6550 | 24000 | 1 | 1 |
63539 | 13449 | 0 | 2000 | DAEWOO | N | 0 | 21 | 240 | 11 | 7 | 34605 | 57241 | 60 | 649 | 19588.54 | 19788 | 683.54 | 60 | 19588.54 | 99 | 4666.67 | 22 | 0 | 4.75 |
7328510 | 14323 | 1 | 1998 | PLYMOUTH | N | 7 | 10 | 60 | NaN | NaN | NaN | NaN | 0 | 613 | 13595 | 11450 | 0 | 60 | 10500 | 92 | 2000 | 19600 | 1 | 1 |
8725187 | 15359 | 1 | 1997 | FORD | N | 3 | 10 | 35 | 5 |
不过看表头有一个空行,打开csv文件 ,发现:
<<<<<<< HEAD |
多了一个这个东东,不知是啥。用记事本打开,第一行也有,<<<<<<< HEAD
删掉后,正常。
问题挺奇怪,第一行有这么个东东,所以读不出来表头也不怪列联表。
记录一下心得。浪费了我1个多小时找答案。