user1999
user1999

Reputation: 199

Struggling extracting columns data from csv file in Python

I have the following csv file where I want to plot each column(temp, current and voltage):

Date/Time:         01/03/2021 11.15.10
Parameter [s]:     6
Time [sec]:        30

Temp[C]    Cur[A]       Volt[V]
-------     -------     -------
-0,022468   0,00        0,00
-0,022481   0,00        0,00
-0,022582   0,00        0,00
-0,021734   0,00        0,00
-0,022541   0,00        0,00
-0,022658   0,00        0,00
-0,022723   0,00        0,00
-0,022253   0,00        0,00
-0,022048   0,00        0,00
-0,022066   0,00        0,00
-0,023073   0,00        0,00

I tried the following:

import pandas as pd
df = pd.read_csv(r'C:\Users\myUser\Desktop\myFile.csv', delimiter="/t", decimal=",") 

But very confused since my file as you see has 3 columns with one tab between col1 and and col 2 and two tabs between col2 and col3. The file has also header first 6 lines.

How can this be done using pandas?

Upvotes: 2

Views: 55

Answers (1)

perl
perl

Reputation: 9941

You can read_csv with skiprows parameter and set '-------' as na_values, so it can be easily dropped with dropna later:

df = pd.read_csv('test.csv', sep='\s+', decimal=',',
                 skiprows=4, na_values='-------')

df = df.dropna()
df.plot()

Output:

picture

Upvotes: 2

Related Questions