Is there any possibility to cut a long vector of output in to specific pieces and save them in different cells in excel?

122 Views Asked by At

I just started to use Python. Actually, I'm setting up a new methodology to read patent data. With textrazor this patent data should be analyzed. I'm interested in getting the topics and save them in a term-document-matrix. It's already possible for me to save the output topics, but only in one big cell with a very long vector. How can I split this long vector, to save the topics in different cells in an Excel file?

If you have any ideas regarding this problem, I would be thankful for your answer. Also, feel free to recommend or help me with my code.

data = open('Patentdaten1.csv')
content= data.read()
table=[]
row = content.split('\n')

for i in range(len(row)):
    column= row[i].split(';')
    table.append(column)

patent1= table[1][1]

import textrazor

textrazor.api_key ="b033067632dba8a710c57f088115ad4eeff22142629bb1c07c780a10"

client = textrazor.TextRazor(extractors= ["entities", "categories", "topics"])

client.set_classifiers(['textrazor_newscodes'])

response = client.analyze(content)

topics= response.topics()

import pandas as pd

df = pd.DataFrame({'topic' : [topics]})

df.to_csv('test.csv') 
1

There are 1 best solutions below

1
Artur On

It's a bit difficult to see exactly what is the problem without an example input and/or output, but saving data to excel via pandas removes any need for intermediate processing: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html

For instance:

import pandas
data = pandas.DataFrame.from_dict({"pantents": ["p0", "p1"], "authors": ["a0", "a1"]})
data.to_excel("D:\\test.xlsx")

Output: enter image description here