【发布时间】:2016-07-26 08:01:02
【问题描述】:
我知道我们可以使用 python 的 csv 模块将 CSV 文件编写为管道分隔文件,但是我想将我的 excel 文件编写为管道分隔的文本文件,是否有类似于 csv 模块的模块可以帮助我实现这一点?
【问题讨论】:
-
要读取 xlsx 文件,请使用 xlrd 模块:pypi.python.org/pypi/xlrd
标签: python-2.7 xlsx
我知道我们可以使用 python 的 csv 模块将 CSV 文件编写为管道分隔文件,但是我想将我的 excel 文件编写为管道分隔的文本文件,是否有类似于 csv 模块的模块可以帮助我实现这一点?
【问题讨论】:
标签: python-2.7 xlsx
你可以使用熊猫模块
# Import modules
import pandas as pd
# read the content of your Excel file into a dataframe
df_sheet = pd.read_excel('test.xlsx', index_col=0)
# write the content of your dataframe into a csv file with the right delimiter
df_sheet.to_csv ("test.csv", sep="|")
【讨论】: