Feynman27
Feynman27

Reputation: 3267

Plot values in specific column range for a particular row in a pandas data frame

I have a 10 rows x 26 columns data set of a country region's oil production between 1990-2011. The first column designates the country region (e.g. Canada), the next 22 columns correspond to oil production between 1990 and 2010, and the last two columns have ratios of oil production in one year relative to another.

My goal is to simply plot the oil production as a function of time separately for each country (i.e. categorize by column 1 and discard the last two columns when plotting). What is the most efficient way to do this?

Upvotes: 1

Views: 2494

Answers (1)

Alexander
Alexander

Reputation: 109546

It seems like you want all of the columns in your data except the last two, so use df.iloc[:, :-2] to select it. You then want to transpose this data so that the dates are now the row and the countries are the columns (use .T). Finally, plot your data.

df.iloc[:, :-2].T.plot()

Upvotes: 1

Related Questions