{"id":2199,"date":"2022-08-06T21:43:14","date_gmt":"2022-08-06T15:43:14","guid":{"rendered":"http:\/\/www.jichangqing.net\/wordpress\/?p=2199"},"modified":"2022-08-06T21:43:14","modified_gmt":"2022-08-06T15:43:14","slug":"%e5%85%b3%e4%ba%8epandas%e7%9a%84%e6%8a%a5%e9%94%99","status":"publish","type":"post","link":"http:\/\/www.jichangqing.net\/wordpress\/?p=2199","title":{"rendered":"\u5173\u4e8epandas\u7684\u62a5\u9519"},"content":{"rendered":"<p>\u4eca\u5929\u57f9\u8bad\u5907\u8bfe\u65f6\uff0c\u505a\u5217\u8054\u8868\u65f6\uff1a<\/p>\n<p>cross_table = pd.crosstab(accepts.bankruptcy_ind,accepts.bad_ind, margins=True)<\/p>\n<p>\u63d0\u793a\u9519\u8bef\uff1a<\/p>\n<pre style=\"color: #000000;\"><span class=\"ansi-red-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b22b31;\">AttributeError<\/span>: 'DataFrame' object has no attribute<\/pre>\n<pre><span class=\"ansi-red-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b22b31;\">ttributeError<\/span>                            Traceback (most recent call last)\r\n<span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">&lt;ipython-input-62-6a7117b99310&gt;<\/span> in <span class=\"ansi-cyan-fg\" style=\"color: #60c6c8;\">&lt;module&gt;<\/span>\r\n<span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">----&gt; 1<\/span>cross_table <span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">=<\/span> pd<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>crosstab<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">(<\/span>accepts<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>bankruptcy_ind<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">,<\/span>accepts<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>bad_ind<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">,<\/span> margins<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">=<\/span><span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">True<\/span><span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">)<\/span>\r\n\r\n<span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">d:\\Anaconda3\\lib\\site-packages\\pandas\\core\\generic.py<\/span> in <span class=\"ansi-cyan-fg\" style=\"color: #60c6c8;\">__getattr__<\/span><span class=\"ansi-blue-intense-fg ansi-bold\" style=\"font-weight: bold; color: #0065ca;\">(self, name)<\/span>\r\n<span class=\"ansi-green-fg\" style=\"color: #00a250;\">   5177<\/span>             <span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">if<\/span> self<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>_info_axis<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>_can_hold_identifiers_and_holds_name<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">(<\/span>name<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">)<\/span><span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">:<\/span>\r\n<span class=\"ansi-green-fg\" style=\"color: #00a250;\">   5178<\/span>                 <span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">return<\/span> self<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">[<\/span>name<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">]<\/span>\r\n<span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">-&gt; 5179<\/span><span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">return<\/span> object<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">.<\/span>__getattribute__<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">(<\/span>self<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">,<\/span> name<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">)<\/span>\r\n<span class=\"ansi-green-fg\" style=\"color: #00a250;\">   5180<\/span> \r\n<span class=\"ansi-green-fg\" style=\"color: #00a250;\">   5181<\/span>     <span class=\"ansi-green-intense-fg ansi-bold\" style=\"font-weight: bold; color: #007427;\">def<\/span> __setattr__<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">(<\/span>self<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">,<\/span> name<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">,<\/span> value<span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">)<\/span><span class=\"ansi-yellow-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b27d12;\">:<\/span>\r\n\r\n<span class=\"ansi-red-intense-fg ansi-bold\" style=\"font-weight: bold; color: #b22b31;\">AttributeError<\/span>: 'DataFrame' object has no attribute 'bankruptcy_ind'<\/pre>\n<p>\u540e\u6765\u53d1\u73b0\uff0c\u6240\u6709\u7684\u5217\u90fd\u8bfb\u4e0d\u51fa\u6765\uff0c\u7f51\u4e0a\u8bf4\uff0c\u8868\u5217\u540d\u6709\u7a7a\u683c\uff0c\u6211\u67e5\u4e86\u4e00\u4e0b\uff0c\u662f\u6ca1\u6709\u7684\u3002<\/p>\n<p>\u4f46\u662f\u7528accepts.head()<\/p>\n<p>\u8fd8\u80fd\u6b63\u5e38\u663e\u793a\uff0c\u6655\u3002<\/p>\n<table class=\"dataframe\" style=\"color: black;\" border=\"1\">\n<thead>\n<tr>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th><\/th>\n<th>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>application_id<\/td>\n<td>account_number<\/td>\n<td>bad_ind<\/td>\n<td>vehicle_year<\/td>\n<td>vehicle_make<\/td>\n<td>bankruptcy_ind<\/td>\n<td>tot_derog<\/td>\n<td>tot_tr<\/td>\n<td>age_oldest_tr<\/td>\n<td>tot_open_tr<\/td>\n<td>tot_rev_tr<\/td>\n<td>tot_rev_debt<\/td>\n<td>tot_rev_line<\/td>\n<td>rev_util<\/td>\n<td>fico_score<\/td>\n<td>purch_price<\/td>\n<td>msrp<\/td>\n<td>down_pyt<\/td>\n<td>loan_term<\/td>\n<td>loan_amt<\/td>\n<td>ltv<\/td>\n<td>tot_income<\/td>\n<td>veh_mileage<\/td>\n<td>used_ind<\/td>\n<td>weight<\/td>\n<\/tr>\n<tr>\n<td>2314049<\/td>\n<td>11613<\/td>\n<td>1<\/td>\n<td>1998<\/td>\n<td>FORD<\/td>\n<td>N<\/td>\n<td>7<\/td>\n<td>9<\/td>\n<td>64<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>506<\/td>\n<td>500<\/td>\n<td>101<\/td>\n<td>650<\/td>\n<td>17200<\/td>\n<td>17350<\/td>\n<td>0<\/td>\n<td>36<\/td>\n<td>17200<\/td>\n<td>99<\/td>\n<td>6550<\/td>\n<td>24000<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>63539<\/td>\n<td>13449<\/td>\n<td>0<\/td>\n<td>2000<\/td>\n<td>DAEWOO<\/td>\n<td>N<\/td>\n<td>0<\/td>\n<td>21<\/td>\n<td>240<\/td>\n<td>11<\/td>\n<td>7<\/td>\n<td>34605<\/td>\n<td>57241<\/td>\n<td>60<\/td>\n<td>649<\/td>\n<td>19588.54<\/td>\n<td>19788<\/td>\n<td>683.54<\/td>\n<td>60<\/td>\n<td>19588.54<\/td>\n<td>99<\/td>\n<td>4666.67<\/td>\n<td>22<\/td>\n<td>0<\/td>\n<td>4.75<\/td>\n<\/tr>\n<tr>\n<td>7328510<\/td>\n<td>14323<\/td>\n<td>1<\/td>\n<td>1998<\/td>\n<td>PLYMOUTH<\/td>\n<td>N<\/td>\n<td>7<\/td>\n<td>10<\/td>\n<td>60<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>613<\/td>\n<td>13595<\/td>\n<td>11450<\/td>\n<td>0<\/td>\n<td>60<\/td>\n<td>10500<\/td>\n<td>92<\/td>\n<td>2000<\/td>\n<td>19600<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>8725187<\/td>\n<td>15359<\/td>\n<td>1<\/td>\n<td>1997<\/td>\n<td>FORD<\/td>\n<td>N<\/td>\n<td>3<\/td>\n<td>10<\/td>\n<td>35<\/td>\n<td>5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u4e0d\u8fc7\u770b\u8868\u5934\u6709\u4e00\u4e2a\u7a7a\u884c\uff0c\u6253\u5f00csv\u6587\u4ef6 \uff0c\u53d1\u73b0\uff1a<\/p>\n<table border=\"0\" width=\"72\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"72\" height=\"18\">&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u591a\u4e86\u4e00\u4e2a\u8fd9\u4e2a\u4e1c\u4e1c\uff0c\u4e0d\u77e5\u662f\u5565\u3002\u7528\u8bb0\u4e8b\u672c\u6253\u5f00\uff0c\u7b2c\u4e00\u884c\u4e5f\u6709\uff0c&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/p>\n<p>\u5220\u6389\u540e\uff0c\u6b63\u5e38\u3002<\/p>\n<p>\u95ee\u9898\u633a\u5947\u602a\uff0c\u7b2c\u4e00\u884c\u6709\u8fd9\u4e48\u4e2a\u4e1c\u4e1c\uff0c\u6240\u4ee5\u8bfb\u4e0d\u51fa\u6765\u8868\u5934\u4e5f\u4e0d\u602a\u5217\u8054\u8868\u3002<\/p>\n<p>\u8bb0\u5f55\u4e00\u4e0b\u5fc3\u5f97\u3002\u6d6a\u8d39\u4e86\u62111\u4e2a\u591a\u5c0f\u65f6\u627e\u7b54\u6848\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u57f9\u8bad\u5907\u8bfe\u65f6\uff0c\u505a\u5217\u8054\u8868\u65f6\uff1a cross_table = pd.crosstab(accepts.bankruptcy_ind,accepts.bad_ind, margins=True) \u63d0\u793a\u9519\u8bef\uff1a AttributeError: &#8216;Da &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-2199","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2199"}],"version-history":[{"count":1,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2199\/revisions"}],"predecessor-version":[{"id":2200,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2199\/revisions\/2200"}],"wp:attachment":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2199"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}