Python 2.7 在python中将excel文件转换为管道分隔文件

Python 2.7 在python中将excel文件转换为管道分隔文件,python-2.7,xlsx,Python 2.7,Xlsx,我知道我们可以使用python的CSV模块将CSV文件编写为管道分隔文件,但是我想将excel文件编写为管道分隔文本文件,是否有类似于CSV模块的模块可以帮助我实现这一点?您可以使用pandas模块 # 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) # w

我知道我们可以使用python的CSV模块将CSV文件编写为管道分隔文件,但是我想将excel文件编写为管道分隔文本文件,是否有类似于CSV模块的模块可以帮助我实现这一点?

您可以使用pandas模块

# 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="|")

您可以使用熊猫模块

# 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="|")

要读取xlsx文件,请使用xlrd模块:要读取xlsx文件,请使用xlrd模块: