相关文章推荐
hi friends
how can i write my sorted list to an exisitng excel file ie sheet name and column number
from openpyxl import load_workbook
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
df = pd.read_excel('python.xlsx', sheet_name='Sheet1')
z= list(df.names)                                                    #Column Name is imported into a List  >  ['Sean', 'Joyce', 'Ruby', 'Pamela']
print(sorted(z,key=len))
#sorted_words=(sorted(z,key=len))
#sorted_words.to_excel('test.xlsx')
thank you for your help Well without seeing the error its hard to say what the problem is. I would start debugging by checking the type of what your trying to write to make sure its what to_excel() function is expecting. I am not sure what exactly it is you are trying to do. It seems as thought you are attempting to take the Column names from python.xlsx, sort them and write them to a different excel file; is that correct?
I have never used Pandas or messed with excel files before but I can tell you this much; to_excel() is expecting type ExcelWriter ie:
# Specify a writer
writer = pd.ExcelWriter('example.xlsx', engine='xlsxwriter')
# Write your DataFrame to a file     
yourData.to_excel(writer, 'Sheet1')
# Save the result 
writer.save()
is there an example that can show me how to type cast, i have not been able to find anything.
That applie to my example.
I sorted my list
I just want to write my list to excel sheet now
 
推荐文章