Panda does not create new lines in Spreadsheet

Asked

Viewed 44 times

1

When creating the program in Python I take some information and put it inside a list.

When trying to write this list in an excel file the data ends up getting all in the same block without creating new lines.

How do I make these data to create new lines with the comma as a separation.

inserir a descrição da imagem aqui

As you can see it does not create new lines, the data on my list are all separated by comma, but Pandas is not creating new lines.

Follow the code:

df = pd.DataFrame({'NAME':[Lawyer_Name],'OAB':[Lawyer_OAB]})

writer = pd.ExcelWriter('OABScrapperExcel.xlsx',engine = 'xlsxwriter')

df.to_excel(writer,sheet_name='LIST OF LAWYERS')

writer.save()

1 answer

1

I could not play the problem with a valid list, the following works:

import pandas as pd

df = pd.DataFrame({'NAME':['Pedro', 'Joaquim'],'OAB':['123', '321']})

writer = pd.ExcelWriter('OABScrapperExcel.xlsx',engine = 'xlsxwriter')

df.to_excel(writer,sheet_name='LIST OF LAWYERS')

writer.save()

What I believe is happening is that you have no lists, but a JSON string for each of the fields.

Thus, it could be fixed by loading the JSON and transforming them into lists:

import json
...
df = pd.DataFrame({'NAME': json.loads(Lawyer_Name),'OAB':json.loads(Lawyer_OAB)})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.