Limit items in a dictionary

0

I'm trying to do data analysis from a self-authored search, the files are already tabbed in .xlsx format. I use openpyxl.

My intention at this point is to get participants' status + their opinion and play in a dictionary.

The problem is that this dictionary is returning only 26 items from random positions.

The solution I am looking for is to: create a diction with states: opinions with all 318 search participants.

My code:

estados = []
u_opiniao = []
estados_x_opiniao = {}

for rowOfCellObjects in ws['B2':'B319']:
    for cellObj in rowOfCellObjects:
        valorestado = str(cellObj.value)
        estados.append(valorestado)

for rowOfCellObjects in ws['J2':'J319']:
    for cellObj in rowOfCellObjects:
        opiniao_do_u = str(cellObj.value)
        u_opiniao.append(opiniao_do_u)

for i in estados:
    estado = i
    for i in u_opiniao:
        opscen = i
        estados_x_opiniao[estado] = opscen

Return

Respostas(total):  318
Total de itens no estados_x_opiniao: 26
    
asked by anonymous 28.04.2018 / 12:23

1 answer

0

Do you have more than one opinion per state? For your code will get only the last opinion of a state and save.

To store more than one opinion per state, create a list with values. Example:

estados_x_opiniao[estado] = [] 
estados_x_opiniao[estado].append(opscen)
    
01.05.2018 / 02:01