我正在尝试编写一个在mac计算机上使用python中的pandas模块写入Excel文件的函数。但是,我收到错误消息:
ModuleNotFoundError:没有名为' pandas'
的模块
pandas已正确安装,我通过以下方式安装:
pip install pandas
为什么我的代码不能运行的任何想法?
import pandas as pd
def excel_write():
#create dataframe
dataframe_date = pd.DataFrame({'Date':[20170712, 20170715, 20170722]})
#create Pandas Excel writer using XlsxWriter as the engine
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlswriter')
#convert the dataframe to XlsWriter Excel object
df.to_excel(writer, sheet_name='LTL Invoices')
#close Pandas Excel writer and output the Excel file
writer.save()
excel_write()
答案 0 :(得分:1)
好的,既然您最终安装了pandas
,据我了解,您实际上并不需要任何奇怪的功能来写信excel
。
当您准备好DataFrame
时,只需使用:
df.to_excel(your_dataframe, sheet_name='LTL Invoices')
如果您仍想继续前进,请尝试将xlswriter
替换为xlsxwriter
:
import pandas as pd
def excel_write():
# Create a Pandas dataframe from the data.
df = pd.DataFrame({'Date':[20170712, 20170715, 20170722]})
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='LTL Invoices')
# Close the Pandas Excel writer and output the Excel file.
writer.save()
excel_write()