如何将数据框附加到另一个数据框?

时间:2021-02-09 07:43:20

标签: python pandas append

我有以下 python pandas 数据框:

master = pd.DataFrame(columns = ['Development id', 'Development Name', 'Integrated Development', 'Developer id', 'Developer', 'Ultimate Developer id', 'Ultimate Developer', 'Development Type', 'Sub Development Type', 'Joint-Venture', 'Year Completed', 'Latitude', 'Longitude', 'No of Floors', 'No of Rooms', 'No of Units/Residences/Lots', 'Gross Floor Area (SQM)', 'Gross Leasable Area', 'Lot Area (SQM)', 'Region', 'City/Municipality', 'CBD', 'Parking vehicles', 'Min. Price per SQM 2020', 'Max. Price per SQM 2020', 'Monthly Min. Rent per SQM 2020', 'Monthly Min Rent per SQM 2020'])

for i in my_list:
    df = pd.read_excel('Template For Developer Footprint.xlsx', sheet_name=i)
    temporary = (df.loc[(df['Development Type'] == 'Hotel & Resort') & df['Development id'].isnull()])
    master.append(temporary)
    display(temporary)

即使我使用附加,空数据框 python 或 Pandas。

1 个答案:

答案 0 :(得分:0)

实际上,您可以将 xlsx 文件的所有工作表连接在一起。然后过滤条件。

xl = pd.ExcelFile('Template For Developer Footprint.xlsx')
df = pd.concat([xl.parse(sheet_name) 
                  for sheet_name in xl.sheet_names ],
                ignore_index=True)

cond = (df['Development Type'] == 'Hotel & Resort') & (df['Development id'].isnull())
cols = ['Development id', 'Development Name', 'Integrated Development', 'Developer id', 'Developer', 'Ultimate Developer id', 'Ultimate Developer', 'Development Type', 'Sub Development Type', 'Joint-Venture', 'Year Completed', 'Latitude', 'Longitude', 'No of Floors', 'No of Rooms', 'No of Units/Residences/Lots', 'Gross Floor Area (SQM)', 'Gross Leasable Area', 'Lot Area (SQM)', 'Region', 'City/Municipality', 'CBD', 'Parking vehicles', 'Min. Price per SQM 2020', 'Max. Price per SQM 2020', 'Monthly Min. Rent per SQM 2020', 'Monthly Min Rent per SQM 2020'])
dfn = df.loc[cond, cols].copy()