从任意行获取pandas中的csv头

时间:2016-09-08 00:44:03

标签: pandas

我有一个看起来像这样的csv:

<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="../../favicon.ico">
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />


  <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

</head>

<body>
  <div class="container-fluid">
    <div class="row no-gutter">
      <div class="col-sm-7">
        <div class="content"></div>
      </div>
      <div class="col-sm-5">
        <div class="row no-gutter">
          <div class="col-sm-12">
            <div class="sidebar-top"></div>
          </div>
        </div>
        <div class="row no-gutter">
          <div class="col-sm-12">
            <div class="sidebar-bottom"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

我可以通过一次调用s,k,i,p # 0. N rows to skip H,E,A,D # 1. header names n,o,n,e # 2. N more rows to skip 1,2,3,4 # 3. Data 6,7,8,9 # 4. ... ... # 5. ... 来读取这些数据吗?我遇到了麻烦,因为我似乎跳过行直到标题然后跳过更多行直到数据

1 个答案:

答案 0 :(得分:3)

你可以传递一个行列表来跳到skiprows,如下所示:

In [2]:pd.read_csv('the_file.csv', skiprows=[0,2])
Out[2]:
   H  E  A  D
0  1  2  3  4
1  6  7  8  9