Python 读取缺少数据的表
是否可以使用基于列的标签读取缺少数据的表?我有下表:Python 读取缺少数据的表,python,pandas,Python,Pandas,是否可以使用基于列的标签读取缺少数据的表?我有下表: Band Band % of Band Peak for % for Area Total No. Pos. Delta Sep. Separ. Height FWHM Gauss Area R
Band Band % of
Band Peak for % for Area Total
No. Pos. Delta Sep. Separ. Height FWHM Gauss Area Ratio Area Area
4 214.01 4.67 3 2.70 5737 1.69 90 3 0.67 10836 30.76
2 212.04 2.70 1 2.70 1391 2.10 90 1 0.67 3254 9.24
3 211.31 1.97 0 8580 1.70 90 0 16255 46.14
1 209.34 0.00 0 2193 2.00 90 0 4882 13.86
我想以专栏的方式阅读。我相信熊猫能做到。我会跳过前两行——但是如何让pandas
以基于列的方式读取剩余的数据呢
任何其他解析此类表(缺少数据)的解决方案也可以。哦,我成功地使用了:
asciitable.read("1.txt", Reader=asciitable.FixedWidthNoHeader,
col_starts=( 8, 16, 22, 28, 36, 44, 49, 55, 60, 67, 74),
col_ends =(14, 21, 25, 34, 42, 48, 53, 58, 65, 73, 80))
丢弃前三行
编辑:
作为注释--同样可以通过熊猫
实现:
pandas.read_fwf("1.txt", widths=[6, 8, 7, 5, 8, 8, 6, 6, 5, 6, 8, 7], skiprows=3)
哦,我设法做到了:
asciitable.read("1.txt", Reader=asciitable.FixedWidthNoHeader,
col_starts=( 8, 16, 22, 28, 36, 44, 49, 55, 60, 67, 74),
col_ends =(14, 21, 25, 34, 42, 48, 53, 58, 65, 73, 80))
丢弃前三行
编辑:
作为注释--同样可以通过熊猫
实现:
pandas.read_fwf("1.txt", widths=[6, 8, 7, 5, 8, 8, 6, 6, 5, 6, 8, 7], skiprows=3)
那么:
import pandas as pd
pd.read_table('example.txt', skiprows=3, sep=r'\s*' )
如果中间只有空间,我认为它不能工作,但很难说出没有样本数据。 < P> >:
import pandas as pd
pd.read_table('example.txt', skiprows=3, sep=r'\s*' )
如果中间只有空格,我认为它不能工作,但没有样本数据是很难说的。
我将在传输中被捕获,但是你可以在最近版本的大熊猫中使用<代码> Read FfWF <代码>。请回答:<代码>熊猫。Read fff(“1。txt”,宽度=[ 6, 8, 7,5, 8, 8,6, 6, 5,6, 8, 7 ],SkiPRWS=3)。有效。我即将被困在运输途中,但你可以在熊猫的最新版本中使用read_-fwf
。请回答:pandas.read_-fwf(“1.txt”,widths=[6,8,7,5,8,8,6,6,5,6,8,7],skiprows=3)
有效。你有样本数据——我在问题中引用了代表性数据。我试过你的例子,它不起作用:它不能考虑某些值丢失。我想我想知道在空白处是否有任何非空格字符-比如标签。但是我想如果有read\u table()
就可以解析它了。你有样本数据——我引用了问题中的代表性数据。我试过你的例子,它不起作用:它不能考虑某些值丢失。我想我想知道在空白处是否有任何非空格字符-比如标签。但我想如果有read_table()
就可以解析它了。pandas
版本工作得很好,widths
参数是可选的,因此跳过它可以让pandas
自行计算。太棒了pandas
版本运行完美,widths
参数是可选的,因此跳过该参数会使pandas
自行计算。令人惊叹的