0

I have a table that is organized as follows

id.salario.idade.mun_trab.mun_res.anos_estudo.sexo.meso_trab.semiarido_trab.faixa_escolaridade
1
1|678|49|250375|250375|1|Masculino|Sertão Paraibano|Sim|Analfabeto
2
2|1351.55|36|251030|251030|1|Masculino|Borborema|Sim|Analfabeto

How do I read the file correctly or modify the columns of that dataframe?

I tried to format the columns and it didn't work.

Phil
  • 7,287
  • 3
  • 36
  • 66
Alex Gois
  • 41
  • 3
  • When you read in your file, you need to specify the correct delimiter to split the columns on – divibisan Mar 22 '23 at 20:58
  • Can you format your example data table correctly. Are the "1" and "2" intended to be on a separate line? If so, what do you intend to do with them? – divibisan Mar 22 '23 at 21:00
  • Edit the header row, to change the delimiters: `id|salario|idade|...`. Then `df = pandas.read_csv(delimiter="|")` – inspectorG4dget Mar 22 '23 at 21:01
  • Read it in with `|` delimter, skip the header row `header=None`, and specify the `names` parameter: `names='id.salario.idade.mun_trab.mun_res.anos_estudo.sexo.meso_trab.semiarido_trab.faixa_escolaridade'.split('.')` If those blank lines exist like that, clean it up after it's in the datraframe. Plenty of ways to skin this cat. – JNevill Mar 22 '23 at 21:04

0 Answers0