0

What i am trying to do is slightly basic, however i am very new to python, and am having trouble. Goal: is to plot the yellow highlighted Row(which i have highlighted, however it will not be highlighted when i need to read the data) on the Y-Axis and plot the "Time" Column on the X-Axis. Here is a photo of the Data, and then the code that i have tried along with its error.

Data

Code

import pandas as pd 
import matplotlib.pyplot as plt
from matplotlib import style 
style.use('ggplot') 




#Reading CSV and converting it to a df(Data_Frame)
df1 = pd.read_csv('Test_Sheet_1.csv', skiprows = 8)

#Creating a list from df1 and labeling it 'Time' 
Time = df1['Time']

print(Time)



#Reading CSV and converting it to a df(Data_Frame)
df2 = pd.read_csv('Test_Sheet_1.csv').T

#From here i need to know how to skip 4 lines. 
#I need to skip 4 lines AFTER the transposition and then we can plot DID and 
Time




DID = df2['Parameters']
print(DID)                 

Error

Error_1

As you can see from the code, right now i am just trying to print the Data so that i can see it, and then i would like to put it onto a graph.

I think i need to use the 'skiplines' function after the transposition, so that python can know where to read the "column" labeled parameters(its only a column after the Transposition), However i do not know how to use the skip lines function after the transposition unless i transpose it to a new Excel Document, but this is not an option.

Any help is very much appreciated, Thank you!

Update

This is the output I get when I add print(df2.columns.tolist())

df2.columns.tolist()) Output

EBELL
  • 51
  • 8
  • 1
    It means there is no column named `'Paremeters'` what does `print(df2.columns.tolist())` show? you may have white spaces – EdChum May 04 '17 at 13:00
  • I have added a section above that shows what is output when i add `print(df2.columns.tolist())` – EBELL May 04 '17 at 13:09
  • Error is clear there is no column named 'Parameters' you need to use the actual column names – EdChum May 04 '17 at 13:11
  • So how would i use the actual column name when the first cell is N/A – EBELL May 04 '17 at 13:15
  • 2
    You need to post raw text that shows what your csv actually is, not an image of what it looks like. For instance you have a lot of duff lines so at what line do you want to actually start reading csv lines? – EdChum May 04 '17 at 13:16
  • Here is a 0Bin copy of the file. you should be able to look and work with the data. https://0bin.net/paste/GnPaMqVQKJ5xUCaM#E4Muy+F44JS4LGpMQSCi+O9g6I2tHrI42U-D2v6st8t – EBELL May 04 '17 at 13:19
  • Also, i would like to read the highlighted names, and plot them on the Y-Axis. I do not know how to tell python to read 4 rows down after it is being transposed – EBELL May 04 '17 at 13:20
  • Isn't transposing the problem: `df2 = pd.read_csv('Test_Sheet_1.csv').T`? Your columns look more like row indices. – IanS May 04 '17 at 13:24
  • So, the only way that i know how to read data in python, is down a column. In this case i need to read the Data across a Row. So i figured i can transpose it and then read down the column (that was originally a row). So if you know how to read across a row without transposing, i would love to learn. – EBELL May 04 '17 at 13:27
  • You should ask another question as this one is not clear, but my guess is that if you remove `.T` your code should work. – IanS May 04 '17 at 13:28
  • Also please visit [how to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – IanS May 04 '17 at 13:29
  • I does not read the correct data. If i remove the T, it will read the column Parameters, but it will read everything vertical. – EBELL May 04 '17 at 13:29
  • in my case, i need to read across the row, not down the column – EBELL May 04 '17 at 13:30
  • You should really ask a new question. The KeyError has been solved. You apparently have another question now, it's not going to be addressed efficiently in the comments. – IanS May 04 '17 at 13:30
  • I still get the key error – EBELL May 04 '17 at 13:34
  • But thank you, i will ask a new question and check out how to make a good pandas example. – EBELL May 04 '17 at 13:35

0 Answers0