我从字典创建了一个pandas数据框,我需要将唯一的列数据复制到同一张工作表中的excel中,但是它只写了一个数据框,在此帮助之后什么也没写! 下面是代码:
import pandas
import csv
import os
act_dict = {'bmc': [], 'adc': [], 'volume': []}
with open('/home/laxmi/Downloads/chadaLookuptablevalueWithAdcreferenceAndBmcid.csv','r') as fp:
contents=csv.reader(fp)
total_count=0
i=0
for row in contents:
if contents.line_num == 1:
continue
data=row
act_dict['bmc'].append(data[0])
act_dict['adc'].append(data[1])
act_dict['volume'].append(data[2])
total_count+=1
os.chdir("/home/laxmi/Documents/volume_analyser_project")
bmc_data = pandas.DataFrame(act_dict)
count=len(bmc_data.bmc.unique())
l1 = bmc_data.bmc.unique()
writer = pandas.ExcelWriter('pandas_multiple.xlsx', engine='xlsxwriter')
count1=(len(l1))
startrow=startcol=0
for i in range(count1):
df_i=bmc_data[bmc_data.bmc==l1[i]]
df_i.to_excel(writer,startrow=0,startcol=startcol+2,sheet_name='Sheet1')
writer.save()
答案 0 :(得分:0)
l1 = bmc_data.bmc.unique()
print(l1)
startcol=startrow = 0
file_name='/home/laxmi/Documents/volume_analyser_project/idmc.xlsx'
writer = pandas.ExcelWriter('idmc.xlsx', engine='xlsxwriter')
count1=(len(l1))
print(count1)
for i in range(count1):
df_i=bmc_data[bmc_data.bmc==l1[i]]
df_i = df_i.sort_values("adc", axis = 0, ascending = True)
df_i.to_excel(writer,sheet_name='Sheet1',startrow=0,startcol=startcol,index=False)
startcol=startcol+4
print(startrow,startcol)
writer.save()