writer. save doenst update excel sheet in loop


writer. save doenst update excel sheet in loop



I'm trying to append the rows of excel sheet using pandas in python.
The problem is the code runs and at the end i only see 1 row added in sheet not all the numbers of rows to which the loop is called to insert the data.



Following is the code of Init where i Read the data frames


def __init__(self,readLink):
self.fileName = 'data.xlsx'
if readLink==0:
self.linksToRead = 10000
else:
self.linksToRead = readLink
self.linkCount = 0
self.wordsList =
self.df = pd.read_excel(self.fileName, sheetname='Sheet1')
if len(self.df) > 0:
self.parsedLinks = self.df['link'].tolist()
else:
self.parsedLinks=
self.urlList =
self.writer = pd.ExcelWriter(self.fileName)
self.Start('https://www.bbc.com/urdu/pakistan-44652896')



Following the the code that runs inside the loop and intend to append the excel rows in sheet using dataframes.


df2 = pd.DataFrame(data = [[URL, ",".join(allKeywords), ",".join(keyphrasesExisted),articleText,"ASDF"]],
columns=['link', 'AllKeywords','PresentKeywords', 'Article','a'])

self.df = pd.concat([self.df,df2])
self.df.to_excel(self.writer,index=False,sheet_name="Sheet1",header=True)
self.writer.save()
print("Added")









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?