使用lambda函数在熊猫read_csv和read_table中指定跳过的行

时间:2020-03-02 18:44:02

标签: pandas csv

我有一个CTD瓶数据文件,我正尝试将其读入数据框。在文件中,行0-261具有我要跳过的元数据,行262具有由多个空格分隔的列标题,行263具有我要跳过的其他列名信息,此后数据看起来像下面的引号。我想阅读每隔一行(只读取以1,2开头的行,等等)。

pd.read_table(r'/home/trent/Documents/assignment/00602.btl',  skiprows=lambda x: (x<262 and x%2!=0), engine='python', sep=' ')

但是我收到一条错误消息:“第6行中预期有6个字段,看到了7个”。 read_csv给了我同样的错误。有办法让它正常工作,还是我不走运?

Blockquote

* Sea-Bird SBE 9 Data File:
* FileName = D:\Data\raw\nbp1701_004.hex
* Software Version Seasave V 7.26.1.8
* Temperature SN = 4209
* Conductivity SN = 2819
* Number of Bytes Per Scan = 40
* Number of Voltage Words = 5
* Number of Scans Averaged by the Deck Unit = 1
* System UpLoad Time = Dec 28 2016 04:15:58
* NMEA Latitude = 59 19.95 S
* NMEA Longitude = 068 29.89 W
* NMEA UTC (Time) = Dec 28 2016  04:15:57
* Store Lat/Lon Data = Append to Every Scan
* SBE 11plus V 5.1g
* number of scans to average = 1
* pressure baud rate = 9600
* NMEA baud rate = 9600
* surface PAR voltage added to scan
* A/D offset = 8
* Latitude/Longitude added to scan
* GPIB address = 1
* advance primary conductivity  0.073 seconds
* advance secondary conductivity  0.073 seconds
* autorun on power up is disabled
* S>
** Ship: RVIB N.B. Palmer
** Cruise: NBP1701
** Station: 00202
** Operator: GA
* System UTC = Dec 28 2016 04:15:58
# interval = seconds: 0.0416667
# start_time = Dec 28 2016 04:15:57 [NMEA time, header]
# <Sensors count="15" >
#   <sensor Channel="1" >
#     <!-- Frequency 0, Temperature -->
#     <TemperatureSensor SensorID="55" >
#       <SerialNumber>4209</SerialNumber>
#       <CalibrationDate>12-Sep-2016 </CalibrationDate>
#       <UseG_J>1</UseG_J>
#       <A>4.34663760e-003</A>
#       <B>6.29548818e-004</B>
#       <C>2.01973913e-005</C>
#       <D>1.53681949e-006</D>
#       <F0_Old>1000.000</F0_Old>
#       <G>4.34644284e-003</G>
#       <H>6.29342788e-004</H>
#       <I>2.01664652e-005</I>
#       <J>1.53546108e-006</J>
#       <F0>1000.000</F0>
#       <Slope>1.00000000</Slope>
#       <Offset>0.0000</Offset>
#     </TemperatureSensor>
#   </sensor>
#   <sensor Channel="2" >
#     <!-- Frequency 1, Conductivity -->
#     <ConductivitySensor SensorID="3" >
#       <SerialNumber>2819</SerialNumber>
#       <CalibrationDate>27-Sep-16</CalibrationDate>
#       <UseG_J>1</UseG_J>
#       <!-- Cell const and series R are applicable only for wide range sensors. -->
#       <SeriesR>0.0000</SeriesR>
#       <CellConst>2000.0000</CellConst>
#       <ConductivityType>0</ConductivityType>
#       <Coefficients equation="0" >
#         <A>0.00000000e+000</A>
#         <B>0.00000000e+000</B>
#         <C>0.00000000e+000</C>
#         <D>0.00000000e+000</D>
#         <M>0.0</M>
#         <CPcor>-9.57000000e-008</CPcor>
#       </Coefficients>
#       <Coefficients equation="1" >
#         <G>-9.85457920e+000</G>
#         <H>1.37960370e+000</H>
#         <I>6.03219116e-004</I>
#         <J>2.50145347e-005</J>
#         <CPcor>-9.57000000e-008</CPcor>
#         <CTcor>3.2500e-006</CTcor>
#         <!-- WBOTC not applicable unless ConductivityType = 1. -->
#         <WBOTC>0.00000000e+000</WBOTC>
#       </Coefficients>
#       <Slope>1.00000000</Slope>
#       <Offset>0.00000</Offset>
#     </ConductivitySensor>
#   </sensor>
#   <sensor Channel="3" >
#     <!-- Frequency 2, Pressure, Digiquartz with TC -->
#     <PressureSensor SensorID="45" >
#       <SerialNumber>1281</SerialNumber>
#       <CalibrationDate>17-May-16</CalibrationDate>
#       <C1>-4.160774e+004</C1>
#       <C2>-4.184703e-001</C2>
#       <C3>1.315700e-002</C3>
#       <D1>3.510400e-002</D1>
#       <D2>0.000000e+000</D2>
#       <T1>3.013996e+001</T1>
#       <T2>-3.939720e-004</T2>
#       <T3>4.255700e-006</T3>
#       <T4>2.107770e-009</T4>
#       <Slope>1.00000000</Slope>
#       <Offset>0.00000</Offset>
#       <T5>0.000000e+000</T5>
#       <AD590M>1.278460e-002</AD590M>
#       <AD590B>-9.255860e+000</AD590B>
#     </PressureSensor>
#   </sensor>
#   <sensor Channel="4" >
#     <!-- Frequency 3, Temperature, 2 -->
#     <TemperatureSensor SensorID="55" >
#       <SerialNumber>5844</SerialNumber>
#       <CalibrationDate>12-Sep-2016 </CalibrationDate>
#       <UseG_J>1</UseG_J>
#       <A>4.36573253e-003</A>
#       <B>6.30179520e-004</B>
#       <C>2.00863167e-005</C>
#       <D>1.50596866e-006</D>
#       <F0_Old>1000.000</F0_Old>
#       <G>4.36553148e-003</G>
#       <H>6.29971788e-004</H>
#       <I>2.00553720e-005</I>
#       <J>1.50462745e-006</J>
#       <F0>1000.000</F0>
#       <Slope>1.00000000</Slope>
#       <Offset>0.0000</Offset>
#     </TemperatureSensor>
#   </sensor>
#   <sensor Channel="5" >
#     <!-- Frequency 4, Conductivity, 2 -->
#     <ConductivitySensor SensorID="3" >
#       <SerialNumber>2569</SerialNumber>
#       <CalibrationDate>20-Sep-16</CalibrationDate>
#       <UseG_J>1</UseG_J>
#       <!-- Cell const and series R are applicable only for wide range sensors. -->
#       <SeriesR>0.0000</SeriesR>
#       <CellConst>2000.0000</CellConst>
#       <ConductivityType>0</ConductivityType>
#       <Coefficients equation="0" >
#         <A>0.00000000e+000</A>
#         <B>0.00000000e+000</B>
#         <C>0.00000000e+000</C>
#         <D>0.00000000e+000</D>
#         <M>0.0</M>
#         <CPcor>-9.57000000e-008</CPcor>
#       </Coefficients>
#       <Coefficients equation="1" >
#         <G>-1.04785719e+001</G>
#         <H>1.58738716e+000</H>
#         <I>9.17747073e-005</I>
#         <J>9.25102032e-005</J>
#         <CPcor>-9.57000000e-008</CPcor>
#         <CTcor>3.2500e-006</CTcor>
#         <!-- WBOTC not applicable unless ConductivityType = 1. -->
#         <WBOTC>0.00000000e+000</WBOTC>
#       </Coefficients>
#       <Slope>1.00000000</Slope>
#       <Offset>0.00000</Offset>
#     </ConductivitySensor>
#   </sensor>
#   <sensor Channel="6" >
#     <!-- A/D voltage 0, Oxygen, SBE 43 -->
#     <OxygenSensor SensorID="38" >
#       <SerialNumber>0186</SerialNumber>
#       <CalibrationDate>14-Sep-16</CalibrationDate>
#       <Use2007Equation>1</Use2007Equation>
#       <CalibrationCoefficients equation="0" >
#         <!-- Coefficients for Owens-Millard equation. -->
#         <Boc>0.0000</Boc>
#         <Soc>0.0000e+000</Soc>
#         <offset>0.0000</offset>
#         <Pcor>0.00e+000</Pcor>
#         <Tcor>0.0000</Tcor>
#         <Tau>0.0</Tau>
#       </CalibrationCoefficients>
#       <CalibrationCoefficients equation="1" >
#         <!-- Coefficients for Sea-Bird equation - SBE calibration in 2007 and later. -->
#         <Soc>4.4810e-001</Soc>
#         <offset>-0.5085</offset>
#         <A>-5.3178e-003</A>
#         <B> 3.0866e-004</B>
#         <C>-4.5954e-006</C>
#         <D0> 2.5826e+000</D0>
#         <D1> 1.92634e-004</D1>
#         <D2>-4.64803e-002</D2>
#         <E> 3.6000e-002</E>
#         <Tau20> 1.1600</Tau20>
#         <H1>-3.3000e-002</H1>
#         <H2> 5.0000e+003</H2>
#         <H3> 1.4500e+003</H3>
#       </CalibrationCoefficients>
#     </OxygenSensor>
#   </sensor>
#   <sensor Channel="7" >
#     <!-- A/D voltage 1, Free -->
#   </sensor>
#   <sensor Channel="8" >
#     <!-- A/D voltage 2, Fluorometer, WET Labs ECO-AFL/FL -->
#     <FluoroWetlabECO_AFL_FL_Sensor SensorID="20" >
#       <SerialNumber>397</SerialNumber>
#       <CalibrationDate>23-Feb-15</CalibrationDate>
#       <ScaleFactor>6.00000000e+000</ScaleFactor>
#       <!-- Dark output -->
#       <Vblank>0.1070</Vblank>
#     </FluoroWetlabECO_AFL_FL_Sensor>
#   </sensor>
#   <sensor Channel="9" >
#     <!-- A/D voltage 3, Transmissometer, WET Labs C-Star -->
#     <WET_LabsCStar SensorID="71" >
#       <SerialNumber>CST-557DR</SerialNumber>
#       <CalibrationDate>27-Jul-2015</CalibrationDate>
#       <M>21.2900</M>
#       <B>-0.1060</B>
#       <PathLength>0.250</PathLength>
#     </WET_LabsCStar>
#   </sensor>
#   <sensor Channel="10" >
#     <!-- A/D voltage 4, PAR/Irradiance, Biospherical/Licor -->
#     <PAR_BiosphericalLicorChelseaSensor SensorID="42" >
#       <SerialNumber>4361</SerialNumber>
#       <CalibrationDate>18- Feb-2015</CalibrationDate>
#       <M>1.00000000</M>
#       <B>0.00000000</B>
#       <CalibrationConstant>2941176471.00000000</CalibrationConstant>
#       <Multiplier>1.00000000</Multiplier>
#       <Offset>-0.52000000</Offset>
#     </PAR_BiosphericalLicorChelseaSensor>
#   </sensor>
#   <sensor Channel="11" >
#     <!-- A/D voltage 5, Free -->
#   </sensor>
#   <sensor Channel="12" >
#     <!-- A/D voltage 6, Altimeter -->
#     <AltimeterSensor SensorID="0" >
#       <SerialNumber>VA-500 51520</SerialNumber>
#       <CalibrationDate>10-Jul-15</CalibrationDate>
#       <ScaleFactor>15.000</ScaleFactor>
#       <Offset>0.000</Offset>
#     </AltimeterSensor>
#   </sensor>
#   <sensor Channel="13" >
#     <!-- A/D voltage 7, Free -->
#   </sensor>
#   <sensor Channel="14" >
#     <!-- SPAR voltage, Unavailable -->
#   </sensor>
#   <sensor Channel="15" >
#     <!-- SPAR voltage, SPAR/Surface Irradiance -->
#     <SPAR_Sensor SensorID="51" >
#       <SerialNumber>6357</SerialNumber>
#       <CalibrationDate>02-17-2015</CalibrationDate>
#       <ConversionFactor>1610.94330200</ConversionFactor>
#       <RatioMultiplier>1.00000000</RatioMultiplier>
#     </SPAR_Sensor>
#   </sensor>
# </Sensors>
# datcnv_date = Jan 15 2017 06:59:34, 7.26.1.8
# datcnv_in = D:\Data\raw\nbp1701_004.hex D:\Data\raw\nbp1701_004.XMLCON
# datcnv_ox_hysteresis_correction = yes
# datcnv_ox_tau_correction = yes
# datcnv_bottle_scan_range_source = BL file
# datcnv_scans_per_bottle = 49
# bottlesum_date = Jan 15 2017 07:06:15, 7.26.1.8
# bottlesum_in = D:\Data\process\odf\nbp1701_004.ros D:\Data\raw\NBP1701_001.XMLCON
    Bottle        Date Potemp090C      Sal00  Sigma-\E900      Sal11       PrDM      DepSM      T090C    C0mS/cm      T190C    C1mS/cm Sbox0Mm/Kg  FlECO-AFL   CStarTr0   Latitude  Longitude      TimeJ       AltM       Spar       Scan
  Position        Time                                                                                                                                                                                                                 
      1    Dec 28 2016     1.4993    34.7191    27.7848    34.7229   2030.643   2001.890     1.6329  31.110722     1.6328  31.113613    177.978     0.0130    99.3677  -59.33321  -68.49718 363.212582      99.33 2.1637e+01      72242 (avg)
              05:06:08                                                  0.476      0.467     0.0003   0.000317     0.0002   0.000263      0.161     0.0044     0.0217    0.00001    0.00000 7.6294e-06       0.04 1.3203e-06         14 (sdev)
      2    Dec 28 2016     1.7677    34.7162    27.7624    34.7196   1764.276   1740.383     1.8834  31.218207     1.8840  31.221402    175.511     0.0125    99.3550  -59.33332  -68.49702 363.217055      99.33 2.1637e+01      81519 (avg)
              05:12:34                                                  0.160      0.157     0.0009   0.000637     0.0005   0.000473      0.218     0.0048     0.0130    0.00000    0.00000 4.4048e-06       0.04 1.3203e-06         14 (sdev)
      3    Dec 28 2016     1.9130    34.7074    27.7441    34.7108   1558.920   1538.553     2.0143  31.240385     2.0142  31.243110    173.492     0.0170    99.3513  -59.33346  -68.49682 363.220728      99.32 2.1637e+01      89134 (avg)
              05:17:51                                                  0.195      0.192     0.0001   0.000178     0.0001   0.000192      0.272     0.0015     0.0219    0.00000    0.00001 4.4048e-06       0.04 1.3203e-06         14 (sdev)
      4    Dec 28 2016     2.0618    34.6821    27.7121    34.6854   1355.648   1338.580     2.1490  31.252503     2.1489  31.255066    169.143     0.0145    99.3333  -59.33360  -68.49671 363.224319      99.33 2.1597e+01      96580 (avg)
              05:23:02                                                  0.358      0.352     0.0001   0.000245     0.0001   0.000234      0.129     0.0036     0.0152    0.00000    0.00001 6.2294e-06       0.04 2.8100e-01         14 (sdev)
      5    Dec 28 2016     2.1374    34.6632    27.6908    34.6664   1257.298   1241.759     2.2180  31.255858     2.2182  31.258608    167.135     0.0172    99.3322  -59.33370  -68.49662 363.226416      99.32 2.1637e+01     100930 (avg)
              05:26:03                                                  0.165      0.163     0.0009   0.000522     0.0009   0.000547      0.140     0.0010     0.0157    0.00000    0.00000 0.0000e+00       0.04 1.3203e-06         14 (sdev)
      6    Dec 28 2016     2.2124    34.6415    27.6673    34.6448   1155.348   1141.345     2.2860  31.254268     2.2859  31.256840    165.499     0.0155    99.3242  -59.33368  -68.49662 363.228580      99.33 2.1637e+01     105417 (avg)
              05:29:10                                                  0.182      0.179     0.0001   0.000141     0.0002   0.000270      0.200     0.0035     0.0176    0.00000    0.00000 9.8495e-06       0.04 1.3203e-06         14 (sdev)
      7    Dec 28 2016     2.2778    34.6142    27.6401    34.6175   1052.834   1040.327     2.3445  31.239225     2.3443  31.241771    164.953     0.0143    99.3115  -59.33366  -68.49662 363.230725      99.32 2.1637e+01     109864 (avg)
              05:32:15                                                  0.354      0.349     0.0003   0.000274     0.0004   0.000355      0.263     0.0036     0.0151    0.00000    0.00000 7.6294e-06       0.04 1.3203e-06         14 (sdev)
      8    Dec 28 2016     2.3493    34.5698    27.5986    34.5732    952.489    941.399     2.4093  31.216492     2.4085  31.218588    165.431     0.0164    99.3046  -59.33360  -68.49671 363.232884      99.32 2.1637e+01     114342 (avg)

0 个答案:

没有答案