我正在尝试写入网络驱动器上的文件。我没有收到任何错误,但无法创建该文件。有什么建议吗?
# 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()
2条答案
按热度按时间mrwjdhj31#
这就是我如何让它在我的Mac上工作的
附言:我无法访问
rwb_list_departments
,所以我只是采取了以下示例 Dataframedf = pd.DataFrame([[1, 2], [3, 4], [5, 6], [7, 8]], columns=["A", "B"])
和文件一起创建的 Dataframe 数据。其余的一切都保持相同,在您的代码。错误似乎是在命令Path
,然后你的方式定义file_to_write
5t7ly7z52#
我不知道为什么,但我的双“\”没有显示在我的答复,但使用双反斜杠,而不是单\