因为手上没有excel来测试,还请楼主自己测试下
import pandas as pd
import os
files = [f for f in os.listdir('.') if f.endswith('.xlsx')]
data_frames = []
for f in files:
df = pd.read_excel(f)
B = df.loc[0, 'B']
data_frames.append(pd.DataFrame({'file': [f], 'B': [B]}))
new_data = pd.concat(data_frames, ignore_index=True)
new_data.to_excel('new_file.xlsx', index=False)