我正在尝试写入网络驱动器上的文件。我没有收到任何错误,但是没有创建文件。有什么建议吗?
# Dataframe
df = pd.DataFrame(rwb_list_departments,columns=['Owned By Team','Major Incident','Status','Priority','Incident ID','Owned By','Short Description','Requester Display Name','Created Date Time','Closed Date Time','Department','Duration','NumDur'])
# writing to local drive as csv works great
df.to_csv('rwb_itsm_processed_tickets.csv',index=False,encoding='utf-8')
# Now write file to networked drive as excel
data_folder = Path('W:/CDS Analytics/RWB')
# combine path and file
file_to_write = data_folder / 'rwb_itsm_processed_tickets.xlsx'
# Specify a writer
writer = pd.ExcelWriter('file_to_write', engine='xlsxwriter')
# Write your DataFrame to a file
df.to_excel(writer,'report')
# Save the result
writer.save()
答案 0 :(得分:0)
这就是我在Mac上运行的方式
# Now write file to networked drive as excel
data_folder ='/Users/myname/Desktop/'
# combine path and file
file_to_write = data_folder + '/rwb_itsm_processed_tickets.xlsx'
P.S:我无法访问rwb_list_departments
,所以我只是遵循以下示例数据帧df = pd.DataFrame([[1, 2], [3, 4], [5, 6], [7, 8]], columns=["A", "B"])
,并且该文件是与数据帧数据一起创建的。其余的一切都与您的代码相同。错误似乎出在命令Path
中,然后出在您定义file_to_write