<p>这是一个非常简单的方法。由于您需要第二个表,并且每个表中都有空格,因此我们可以分步骤解决此问题:</p>
<p>1-读入整个数据帧</p>
< p > 2查找空白行</p>
<P> 3 -在空白行</p>之间读取
<pre><code>import pandas as pd
# read in dataframe
# using skip_blank_lines=False makes sure to read all the nulls
# using usecols ensures we only use the first three columns
df = pd.read_excel(r'path_to_your.xlsx'
, skip_blank_lines=False, usecols='A:C')
A B C
0 1 4 7
1 2 5 8
2 3 6 9
3 NaN NaN NaN
4 E F G
5 1 2 3
6 4 5 6
7 NaN NaN NaN
8 H I J
9 a d g
10 b e h
11 c f i
# get index of first entire NULL row, add 2 to correct skip these rows
first_val = df.loc[df.isna().all(axis=1)].index[0]+2
# re-read the file. Skiping the rows we just found the nulls for
df2 = pd.read_excel(r'path_to_your.xlsx', skiprows=first_val)
E F G
0 1 2 3
1 4 5 6
2 NaN NaN NaN
3 H I J
4 a d g
5 b e h
6 c f i
# now just read up to the blank line
# using iloc, we use the first row (0) and go up until the first blank line
# since the first blank line is the end of the dataframe it will return our answer
df2.iloc[0:df2.loc[df2.isna().all(axis=1)].index[0]]
E F G
0 1 2 3
1 4 5 6
</code></pre>