[英]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):我有以下 csv 文件,我想要 plot 每列(温度、电流和电压):
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.但是非常困惑,因为您看到的我的文件有 3 列,其中 col1 和 col 2 之间有一个选项卡,col2 和 col3 之间有两个选项卡。 The file has also header first 6 lines.
该文件还有 header 前 6 行。
How can this be done using pandas?如何使用 pandas 做到这一点?
You can read_csv
with skiprows
parameter and set '-------' as na_values
, so it can be easily dropped with dropna
later:您可以使用
read_csv
参数skiprows
并将 '--------' 设置为na_values
,因此以后可以使用dropna
轻松删除它:
df = pd.read_csv('test.csv', sep='\s+', decimal=',',
skiprows=4, na_values='-------')
df = df.dropna()
df.plot()
Output: Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.