2

我正在尝试写入网络驱动器上的文件。我没有收到任何错误,但没有创建文件。有什么建议么?

# 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()
4

1 回答 1

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'

PS:我无法访问rwb_list_departments,所以我只使用了以下示例数据框df = pd.DataFrame([[1, 2], [3, 4], [5, 6], [7, 8]], columns=["A", "B"]),并且该文件是与数据框数据一起创建的。其余所有内容都与您的代码中的相同。错误似乎在命令中Path,然后是您定义的方式file_to_write

于 2018-08-01T23:18:50.337 回答