【问题标题】:How to choose a header in a specific row to plot a csv using python?如何选择特定行中的标题以使用 python 绘制 csv?
【发布时间】:2022-07-07 22:17:15
【问题描述】:

到目前为止做了什么

我想将第 15 行作为我的标题,并知道该怎么做。每当我打印标题时,我都会将标题设置为第 1 行的标题,但我想要第 15 行:时间;压力P9;压力P10;压力P11;压力P12;压力P13;压力P14。这是我的标题,所以我可以制作一个情节

#Imorting modules

import csv 
import pandas as pd 
import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np
import os

#changing directory
os.chdir('C:/Users/A429039/OneDrive - Volvo 
Group/Python/test/Conditioned/')
print("Directory changed")

#opening file  
str_filename ='1.csv'
fh = open(str_filename)
#reading file and printing header*   
csv_reader = csv.reader(fh)
csv_header = next(csv_reader)
print(csv_header) 
#i want to choose which row header should be choosen

#reading file and skiping 43 row to the data for the plot

df_sig = 
pd.read_csv(str_filename,header=None,skiprows=43,names=csv_header)
print(df_sig)

#creating and labeling plot  

df_sig.time.plot()
plt.xlabel('PressureP9', 'PressureP10',' PressureP11',' 
PressureP12','PressureP13',' PressureP14')
plt.ylabel('Time')
1. 1.csv - data;
2.Conditioned
3.Kopplingstest
4.100 samples per second
5.X axis ;Sekunder
6.Y axis Pressure; MPa
7.Marker;PKA 330 mA;0
8.Limits;;0.24;0.47
9.Marker;PKA 480 mA;5.52
10.Limits;;0.79;1.02
11.Marker;PKA 0 mA;9.55
12.Limits;;-0.02;0.02
13.Marker;PKB 330 mA;19.68
14.Limits;;0.24;0.47
15.Time; PressureP9; PressureP10; PressureP11; PressureP12; PressureP13; PressureP14
16. sek;;;;;;
17. 0;0.00243070783162513;0.00233563632928169;0.00123072609589125;0.00320555604269979;0.00296585321291742;0.0043743342295986
18. 0.01;0.00228772501626784;0.00206085558426761;0.00259819953464657;0.00264806803307766;0.0037747222720147;0.00395101155836289
19. 0.02;0.00228772501626784;0.00219824595676144;0.00232470484698932;0.00334492804525022;0.00350509925226605;0.00451544178686117
20. 0.03;0.00243070783162513;0.00315997856495542;0.00150422078373624;0.00320555604269979;0.00323547623256681;0.0043743342295986
21. 
0.04;0.00228772501626784;0.00164868446694355;0.00218795750314305;0.00306618404020731;0.00296585321291742;0.00423322667242809
**# i want this as my header** 15.Time; PressureP9; PressureP10; PressureP11; PressureP12; PressureP13; PressureP14

【问题讨论】:

    标签: python pandas csv matplotlib


    【解决方案1】:

    代码很难理解。请修复。

    【讨论】:

    • 请不要回答评论/问题。可以理解的是,您的代表太低而无法发表评论,但这并不意味着应该使用答案来使 cmets 作为替代方案。最好把它删掉。
    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 2020-05-26
    • 1970-01-01
    • 2021-07-08
    相关资源
    最近更新 更多