Index column using data from my csv file

Asked

Viewed 119 times

0

Good night to you all!

I opened a csv file in python using the following command:

caminhoarquivo = r'C:\Users\user\Desktop\teste.csv'

basedados = pd.read_csv(caminhoarquivo,sep=';',decimal=',', encoding='latin-1')

But in the first row (label of csv) it inserts "index" and considers in this column the data of the first column of my csv, leaving the last column of csv without information. I would like someone to help me insert numbers into this "index" column instead of using data from my file. So as not to move the label, leaving the last column without information.

File example:

Ponto de Medição|      Data          |Hora|Consumo|Status
  User1         |   30/11/2018       | 24 |  23,5 |  OK 
  User1         |   30/11/2018       |  1 |  14,8 |  OK
  User1         |   30/11/2018       |  2 |  48,6 |  OK
  User1         |   30/11/2018       |  3 |  92,3 |  OK
  User1         |   30/11/2018       |  4 |  76,2 |  OK

After opening in Python:

  Index         |  Ponto de Medição|  Data|   Hora|Consumo|Status
  User1         |   30/11/2018       | 24 |  23,5 |  OK   |
  User1         |   30/11/2018       |  1 |  14,8 |  OK   |
  User1         |   30/11/2018       |  2 |  48,6 |  OK   |
  User1         |   30/11/2018       |  3 |  92,3 |  OK   |
  User1         |   30/11/2018       |  4 |  76,2 |  OK   |

Thanks in advance!

  • And like this file of yours CSV ? It would have to put a part or an example of how this ?

  • I inserted part of the csv file. When I open it in Python it displaces the first line and inserts "index" making 'User1" in the column labeled "index". So the "status" column is empty.

  • Felipe, it would be important to put the text instead of image, due to restrictions I can’t see the image.

  • I entered an example.

  • I tested here and for me this normal, your code is only the one that put here or has more code?

No answers

Browser other questions tagged

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