0

I'm trying to use the following code to see the first rows of my dataframe:

import pandas as pd
file = "dados_completo.csv"
path = "C:\Delos\Dados\\"
col_names = ['Nome', 'Votos', 'Partido', 'Status', 'Nome Completo', 'Idade', 'Nascimento', 'Naturalidade', 'Civil', 'Ocupação', 'Grau', 'url']
df = pd.read_csv(path + file, encoding = 'cp1252', delimiter = ',', header = None, names = col_names)
print(df.head())

Although I'm getting the following:

  ...
0 ...
1 ...
2 ...
3 ...
4 ...

[5 rows x 12 columns]

Why is this happening? Isn't it supposed to show the columns and values?

Moreover, when I print the df everything seems to be ok:

                              Nome        Votos  Partido      Status                            Nome Completo    Idade  Nascimento             Naturalidade              Civil                              Ocupação                           Grau                                                url
0                  Taliria Petrone  5,121 VOTOS     PSOL      ELEITO                   Talíria Petrone Soares  33 anos  09/04/1985      Rio de Janeiro - RJ           Solteira             Professor de Ensino Médio              Superior Completo   https://www.eleicoes2016.com.br/taliria-petrone/
1              Paulo Eduardo Gomes  5,083 VOTOS     PSOL      ELEITO                      Paulo Eduardo Gomes  67 anos  24/10/1950             Niteroi - RJ             Casado                              Vereador              Superior Completo  https://www.eleicoes2016.com.br/paulo-eduardo-...
2                         Bagueira  4,675 VOTOS       SD      ELEITO       Paulo Roberto Mattos Bagueira Leal  59 anos  05/06/1959             Niteroi - RJ             Casado                              Vereador              Superior Completo          https://www.eleicoes2016.com.br/bagueira/
3                  Renato Cariello  4,575 VOTOS      PDT      ELEITO     Renato Ferreira de Oliveira Cariello  51 anos  06/09/1966             Niterói - RJ             Casado                              Vereador              Superior Completo   https://www.eleicoes2016.com.br/renato-cariello/
4                Dr. Emanuel Rocha  4,518 VOTOS       SD      ELEITO            Emanuel Jorge Mendes da Rocha  66 anos  26/06/1952             Niteroi - RJ              Viúvo                            Economista              Superior Completo  https://www.eleicoes2016.com.br/dr-emanuel-rocha/
5                    Veronica Lima  4,501 VOTOS       PT      ELEITO                 Veronica dos Santos Lima  44 anos  04/11/1973             Niteroi - RJ           Solteira                              Vereador            Superior Incompleto     https://www.eleicoes2016.com.br/veronica-lima/
2-D
  • 89
  • 10
  • "when I print the df everything seems to be ok" so what's the exact problem you have? – cs95 Jul 01 '18 at 00:08
  • I'm trying to figure out why head method it's not working as it supposed to be. Also, after adding "del df['url']", print(df) is stopped working too. It gives me the same result of head. – 2-D Jul 01 '18 at 00:15
  • 1
    Try to see if the following thread applies to you: https://stackoverflow.com/questions/13085709/df-head-sometimes-doesnt-work-in-pandas-python – BossaNova Jul 01 '18 at 06:17
  • Although it's a hypothesis, it doesn't make full sense. After all, why would the terminal be wide enough to show the full df but not to show only the first rows? – 2-D Jul 01 '18 at 15:55

0 Answers0