0

I'm trying to create a line plot (time series) from a filtered data frame that is 17 rows x 33 columns.

To provide some background, I am tracking gene expression over certain time points. Every row in this data frame corresponds to a particular exon. Every column on this data frame corresponds to a time-point, while the VALUES INSIDE the columns correspond to level of gene expression.

This is what my data frame looks like: Image depicting the data frame I'm working with

I want to create a line graph where every line corresponds to a row on this data frame (exon), while the y-values correspond to level of gene expression (values inside each column).

I'm trying to get a resulting graph that would something like this:

enter image description here

Is there anyway to do this? I've tried to set the x and y axes individually but I think the error might stem from using labels and integer-values interchangeably. This is the method I tried using:

df2.plot(x=df2['0'], y=df2['38', '56', '65', '79', '99', '110', '128', '138', 
                       '146', '171', '183', '198', '206', '218', '231', '238', 
                       '258', '276', '283', '303', '316', '331', '343', '367', 
                       '379', '383', '412', '430', '438', '471', '484', '496', '521'])

But this produces this instead:

An image of the failed line plot attempt

Any help would be greatly appreciated.

1 Answer 1

1

If I got the problem correctly, transpose should help here:

enter image description here

enter image description here

P.S. It was randomly generated data

UPDATE:

Will reflect comment here for the sake of consistency. Seems like the column name is a string in your case, here is how it should work in that case

enter image description here

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

3 Comments

Thanks for the reply, that definitely looks like what I'm trying to achieve! Unfortunately I tried using this method but got "KeyError: None of [0] are in the columns." I think the issue may be that the first column is named "0" ? Not sure how I would change that though.
Good. In my case the column name was integer. Looks like this option should work for you: df.set_index("0")
Thanks for the help. I've discovered that the first column is actually an index, which is why it's so finicky with the code. I have changed the name of the index by using df2.index.name = 'exon' and then ran your code. It works thanks!

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.