-1
I have the following problem:
I have a csv file with multiple numbers.
I read this file, pass a header and make the separation The problem happens when I try to save this data in a new csv file.
Separation does not occur and ends up being equal to the previous file before editing
Follow the code I made:
import pandas as pd
uri = "dados.csv"
cabecalho = ['Axis1', 'Axis2', 'Axis3', 'Steps', 'Lux', 'Inclinometer Off', 'Inclinometer Standing', 'Inclinometer Sitting', 'Inclinometer Lying']
dados = pd.read_csv(uri, sep=',', header=None, names=cabecalho, index_col=0)
dados.to_csv('dadosLimpos.csv', sep=',')
Example of the CSV:
489,768,860,3,28,0,10,0,0
644,796,684,7,56,0,10,0,0
1219,1294,1721,7,74,0,10,0,0
495,770,556,3,22,0,10,0,0
74,241,386,2,0,0,10,0,0
1153,781,837,7,63,0,10,0,0
191,365,382,2,55,0,10,0,0
27,733,185,1,73,3,0,0,7
7,554,114,1,98,8,0,0,2
213,974,574,4,96,0,10,0,0
The intention was to create the header in the new file and keep the numbers?
– Daniel Mendes
Yes. The header comes normal, but it does not separate the correct numbers in each column. Everyone is saved in "Axis1".
– Maick Henrique
You put in the CSV you’re using, I ran a test and it was all right, I didn’t change anything in your code. If the CSV is too large, just put a stretch, a few lines.
– Daniel Mendes
I edited the question with some csv data
– Maick Henrique
Is this the expected result? https://i.stack.Imgur.com/j8U71.png
– Daniel Mendes
It’s in that shape.
– Maick Henrique
So, I didn’t change anything... If you are opening this generated CSV where? In Excel?
– Daniel Mendes
Yes. He saves with that new name and I open it
– Maick Henrique
Maick, this is just Excel itself, it is interpreting the CSV with the delimiter being semicolon, I believe it is the default in the installation BR. Unfortunately at the moment I don’t have an Excel to guide you how to exchange this, but if you want to do a test, change the comma of csv by semicolon and open again.
– Daniel Mendes
I had done this test. I replaced all the commas with ; . The header it separated, column by column, minus the numbers. I will try to see his settings here. Thank you very much
– Maick Henrique