Accessing data in CSV

Asked

Viewed 38 times

0

The code is to separate the values of each state in different lists, so the variable 'o' changes all once the state acronym changes and tells which list the values will be. It works until the penultimate change but in the last it returns the error Keyerror: 5596. No problem in the file as I can access this line through separate prints and appends.

import pandas as pd
import matplotlib.pyplot as plt
dados=pd.read_csv('salarios.csv',sep=',')

tamanho=len(dados)
anos=[]
for i in range(27):
    anos.append([])
o=0

sigla=dados['Sigla']

for i in range(tamanho):
    if sigla[i]!=sigla[i+1]:
        print(sigla[i])
        o=o+1`
  • Only squares, good morning! Can you make the dataset available? Hug!

  • I managed to solve the problem, where I set the size of my file he counted the line of the headers, when he will separate the 'o' he counted an extra line that was empty

  • Great then! I ordered the dataset to try to solve the problem in another way since you use pandas to store the structure. Hug!!

No answers

Browser other questions tagged

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