2

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. Can you also tell me how can we plot only one particular column? df[1] or df(1) doesnt work
@user1999 For plotting a column by name you can use loc for plotting a column by name or iloc for plotting it by number: df.loc[:, col_name].plot() or df.iloc[:, col_number].plot()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.