用 pandas 提取xls文件后,如何从输出中删除编号[Python] [英] How remove numbering from output after extract xls file with pandas [Python]
问题描述
我有一个Python脚本,可以从Excel .xls
文件中提取特定的列,但是输出在提取的信息旁边有一个编号,因此我想知道如何格式化输出这样它们就不会出现.
我的实际代码是这样:
sys.argv中我的 :file_name = sys.argv [1]工作簿= pd.read_excel(file_name)df = pd.DataFrame(工作簿,专栏= ['NOM_LOGR_COMPLETO'])df = df.drop_duplicates()df = df.dropna(轴= 0,操作方式=任何",脱粒=无,子集=无,原位= False)打印(df)
我当前的输出:
1 Street Alpha< br>2街布拉沃
但是我需要的结果是:
街道Alpha< br>布拉沃街
没有编号,只有街道名称.
谢谢!
我相信您想要一个没有索引的数据框.请注意,没有索引就不能拥有 DataFrame
,它们是 DataFrame
的重点.因此,对于您的情况,您可以采用:
print(df.values)
查看不带索引列的数据框.要保存不带索引的输出,请使用:
writer = pd.ExcelWriter("dataframe.xlsx",engine ='xlsxwriter')df.to_excel(writer,sheet_name = df,index = False)writer.save()
其中 file_name ="dataframe.xlsx"
.
更多参考资料可以在以下位置找到:
如何在不使用索引的情况下打印pandas DataFrame
I have a Python Script that extracts a specific column from an Excel .xls
file, but the output has a numbering next to the extracted information, so I would like to know how to format the output so that they don't appear.
My actual code is this:
for i in sys.argv:
file_name = sys.argv[1]
workbook = pd.read_excel(file_name)
df = pd.DataFrame(workbook, columns=['NOM_LOGR_COMPLETO'])
df = df.drop_duplicates()
df = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
print(df)
My current output:
1 Street Alpha <br>
2 Street Bravo
But the result I need is:
Street Alpha <br>
Street Bravo
without the numbering, just the name of the streets.
Thanks!
I believe you want to have a dataframe without the index. Note that you cannot have a DataFrame
without the indexes, they are the whole point of the DataFrame
. So for your case, you can adopt:
print(df.values)
to see the dataframe without the index column. To save the output without index, use:
writer = pd.ExcelWriter("dataframe.xlsx", engine='xlsxwriter')
df.to_excel(writer, sheet_name = df, index=False)
writer.save()
where file_name = "dataframe.xlsx"
for your case.
Further references can be found at:
How to print pandas DataFrame without index
Printing a pandas dataframe without row number/index
disable index pandas data frame
Python to_excel without row names (index)?
这篇关于用 pandas 提取xls文件后,如何从输出中删除编号[Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!