1

I am new python data analysis and having some problems to get the required data in specific format.

My data is in following format. ( please check the attached link for data in csv format as the data is quite large)

enter image description here

I used following commands to print the csv data in the above format

address = 'C:\Barchatdata.csv' data_c = pd.read_csv(address)

Now i want to apply if condition on Energy_Supply_per_capita >280 and then print index column, contry_area, Energy_Supply_per_capita and Avg_GDP columns.

i tried following command

data_c.loc[data_c['Energy_Supply_per_capita'] > 280, 'Energy_Supply_per_capita']

but got only index and Energy_Supply_per_capita columns.

How i can get the required results?

Thank you in advance.

link to csv file

hpaulj
  • 221,503
  • 14
  • 230
  • 353
siddpro
  • 81
  • 9
  • Possible duplicate of: http://stackoverflow.com/questions/19237878/subsetting-a-python-dataframe – sgrg Apr 13 '17 at 17:27

1 Answers1

2

You can use query

cols = ['Country_Area', 'Energy_Supply_per_capita', 'Avg_GDP']
data_c.query('Energy_Supply_per_capita > 280')[cols]

Or equivalently with a boolean series and loc

cols = ['Country_Area', 'Energy_Supply_per_capita', 'Avg_GDP']
data_c.loc[data_c.Energy_Supply_per_capita > 280, cols]
piRSquared
  • 285,575
  • 57
  • 475
  • 624