Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在python中将excel文件转换为管道分隔文件_Python 2.7_Xlsx - Fatal编程技术网

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模块: