python导入文件时,路径读取出错

错误

在用python读取桌面文件order.xlsx时出现错误

C:\Users\weihoo\Desktop\orders.xlsx

 File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

问题原因及解决方案

由于python的“\”是转义字符,\u表示其后是UNICODE编码,因此\Users在这里会报错,在字符串前面加个r表示就可以了

dfexcel = pd.DataFrame(pd.read_excel(r"C:\Users\weihoo\Desktop\orders.xlsx"))

dfexcel
      订单编码       订单日期     要求发货日期     实际发货日期        订单状态                                                 备注  顾客编码
0    10100 2003-01-06 2003-01-13 2003-01-10     Shipped                                                NaN   363
1    10101 2003-01-09 2003-01-18 2003-01-11     Shipped                             Check on availability.   128
2    10102 2003-01-10 2003-01-18 2003-01-14     Shipped                                                NaN   181
3    10103 2003-01-29 2003-02-07 2003-02-02     Shipped                                                NaN   121
4    10104 2003-01-31 2003-02-09 2003-02-01     Shipped                                                NaN   141
5    10105 2003-02-11 2003-02-21 2003-02-12     Shipped                                                NaN   145
6    10106 2003-02-17 2003-02-24 2003-02-21     Shipped                                                NaN   278
7    10107 2003-02-24 2003-03-03 2003-02-26     Shipped  Difficult to negotiate with customer. We need ...   131
8    10108 2003-03-03 2003-03-12 2003-03-08     Shipped                                                NaN   385
9    10109 2003-03-10 2003-03-19 2003-03-11     Shipped  Customer requested that FedEx Ground is used f...   486
10   10110 2003-03-18 2003-03-24 2003-03-20     Shipped                                                NaN   187
11   10111 2003-03-25 2003-03-31 2003-03-30     Shipped                                                NaN   129
12   10112 2003-03-24 2003-04-03 2003-03-29     Shipped  Customer requested that ad materials (such as ...   144
13   10113 2003-03-26 2003-04-02 2003-03-27     Shipped                                                NaN   124
14   10114 2003-04-01 2003-04-07 2003-04-02     Shipped                                                NaN   172
15   10115 2003-04-04 2003-04-12 2003-04-07     Shipped                                                NaN   424
16   10116 2003-04-11 2003-04-19 2003-04-13     Shipped                                                NaN   381
17   10117 2003-04-16 2003-04-24 2003-04-17     Shipped                                                NaN   148
18   10118 2003-04-21 2003-04-29 2003-04-26     Shipped  Customer has worked with some of our vendors i...   216
19   10119 2003-04-28 2003-05-05 2003-05-02     Shipped                                                NaN   382
20   10120 2003-04-29 2003-05-08 2003-05-01     Shipped                                                NaN   114
21   10121 2003-05-07 2003-05-13 2003-05-13     Shipped                                                NaN   353
22   10122 2003-05-08 2003-05-16 2003-05-13     Shipped                                                NaN   350
23   10123 2003-05-20 2003-05-29 2003-05-22     Shipped                                                NaN   103
24   10124 2003-05-21 2003-05-29 2003-05-25     Shipped  Customer very concerned about the exact color ...   112
25   10125 2003-05-21 2003-05-27 2003-05-24     Shipped                                                NaN   114
26   10126 2003-05-28 2003-06-07 2003-06-02     Shipped                                                NaN   458
27   10127 2003-06-03 2003-06-09 2003-06-06     Shipped  Customer requested special shippment. The inst...   151
28   10128 2003-06-06 2003-06-12 2003-06-11     Shipped                                                NaN   141
29   10129 2003-06-12 2003-06-18 2003-06-14     Shipped                                                NaN   324
..     ...        ...        ...        ...         ...                                                ...   ...
296  10396 2005-03-23 2005-04-02 2005-03-28     Shipped                                                NaN   124
297  10397 2005-03-28 2005-04-09 2005-04-01     Shipped                                                NaN   242
298  10398 2005-03-30 2005-04-09 2005-03-31     Shipped                                                NaN   353
299  10399 2005-04-01 2005-04-12 2005-04-03     Shipped                                                NaN   496
300  10400 2005-04-01 2005-04-11 2005-04-04     Shipped  Customer requested that DHL is used for this s...   450
301  10401 2005-04-03 2005-04-14        NaT     On Hold  Customer credit limit exceeded. Will ship when...   328
302  10402 2005-04-07 2005-04-14 2005-04-12     Shipped                                                NaN   406
303  10403 2005-04-08 2005-04-18 2005-04-11     Shipped                                                NaN   201
304  10404 2005-04-08 2005-04-14 2005-04-11     Shipped                                                NaN   323
305  10405 2005-04-14 2005-04-24 2005-04-20     Shipped                                                NaN   209
306  10406 2005-04-15 2005-04-25 2005-04-21    Disputed  Customer claims container with shipment was da...   145
307  10407 2005-04-22 2005-05-04        NaT     On Hold  Customer credit limit exceeded. Will ship when...   450
308  10408 2005-04-22 2005-04-29 2005-04-27     Shipped                                                NaN   398
309  10409 2005-04-23 2005-05-05 2005-04-24     Shipped                                                NaN   166
310  10410 2005-04-29 2005-05-10 2005-04-30     Shipped                                                NaN   357
311  10411 2005-05-01 2005-05-08 2005-05-06     Shipped                                                NaN   233
312  10412 2005-05-03 2005-05-13 2005-05-05     Shipped                                                NaN   141
313  10413 2005-05-05 2005-05-14 2005-05-09     Shipped  Customer requested that DHL is used for this s...   175
314  10414 2005-05-06 2005-05-13        NaT     On Hold  Customer credit limit exceeded. Will ship when...   362
315  10415 2005-05-09 2005-05-20 2005-05-12    Disputed  Customer claims the scales of the models don't...   471
316  10416 2005-05-10 2005-05-16 2005-05-14     Shipped                                                NaN   386
317  10417 2005-05-13 2005-05-19 2005-05-19    Disputed  Customer doesn't like the colors and precision...   141
318  10418 2005-05-16 2005-05-24 2005-05-20     Shipped                                                NaN   412
319  10419 2005-05-17 2005-05-28 2005-05-19     Shipped                                                NaN   382
320  10420 2005-05-29 2005-06-07        NaT  In Process                                                NaN   282
321  10421 2005-05-29 2005-06-06        NaT  In Process  Custom shipping instructions were sent to ware...   124
322  10422 2005-05-30 2005-06-11        NaT  In Process                                                NaN   157
323  10423 2005-05-30 2005-06-05        NaT  In Process                                                NaN   314
324  10424 2005-05-31 2005-06-08        NaT  In Process                                                NaN   141
325  10425 2005-05-31 2005-06-07        NaT  In Process                                                NaN   119

[326 rows x 7 columns]
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值