擅长:python、mysql、java
<p>您可能需要<code>pip install xlrd</code>才能使用.xlsx文件
否则,将数据保存到.csv并使用<code>pd.read_csv()</code></p>
<p>另外,你发布的数据似乎有8列,但我认为只有4列,对吗?
如果没有,那么就需要解决重复变量名的问题。在</p>
<pre><code>import pandas as pd
with open('subjects_visit2.txt', 'r') as infile:
# put contents into a list without the newlines
subject_list = infile.read().splitlines()
# convert subject_list to a list of integers
subject_list = [int(subject) for subject in subject_list]
# open data file and show 1st 5 rows
df = pd.read_excel('amygdala_mPFC_data_pandas.xlsx')
print(df.head())
# uses .query() which allows easy to read syntax.
# Note: The @ symbol allows access to objects not defined in the data frame
new_df = df.query('Subject in @subject_list')
print(new_df)
</code></pre>
<p>输出如下所示:</p>
^{pr2}$