How to turn a list into dataframe pandas?

Asked

Viewed 4,221 times

0

I am new in the language, after the execution of the following code, the result of the append made is a list. I needed this information in dataframe, but so far I could not find a way to convert without losing information. Whenever I try to move to dataframe (even with Concat tried), only one of the lines appears in it.

appended_data = []
for i in a:
 url = 'https://www.receitaws.com.br/v1/cnpj/{0}'.format(i)
 req = requests.get(url)
 code = req.status_code
 if code == 200:
     html = req.text
     receita = json.loads(html)
 dataframe=pd.DataFrame(
        {
        'Atividade Principal': [receita['atividade_principal'][0]['text']],
        'Situação cadastral': [receita['situacao']],
        'Status': [receita['status']],
        'Sócio 1 (role)': [receita['qsa'][0]['qual']],
        'Sócio 1': [receita['qsa'][0]['nome']],
        'Sócio 2 (role)': [receita['qsa'][1]['qual']],
        'Sócio 2': [receita['qsa'][1]['nome']],
        'Nome': [receita['nome']],
        'UF': [receita['uf']]

        }
    )
appended_data.append(dataframe)
appended_data

How I turn the list below into dataframe? inserir a descrição da imagem aqui

1 answer

2

do not forget to convert list to numpy arraye after reshape

n = pd.DataFrame(np.array(lista).reshape(3,3), columns = list("ABC"))
print (n)
   A  B  C
0  1  2  3
1  4  5  6
2  7  8  9

Browser other questions tagged

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