Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Selecting Few Columns from a dataframe
Hi All,
I am very new to python.

While in other languages, it is easy once the data is loaded to select only few columns of the entire dataset as i am newbie, i am finding a bit difficult to do this.
Below is the dataset i have:
[skip_rows = pd.read_excel("Org_Data.xlsx", sheet_name=2, skiprows=5)
now this file have 42 columns and i need to see only 4th to 8th column from all the columns.
I am able to do this if i select and create a new dataframe but not on the existing skip_rows data.

My code below:
[subset_columns = pd.read_excel("Org_Data.xlsx", parse_cols=3:7)]
Please suggest if the above is possible without creating a new dataframe.
Thanks, Shivi
Once you read entire sheet

df = pd.read_excel("Org_Data.xlsx", sheet_name=2, skiprows=5)
you can select desired columns using .iloc:

df.iloc[:, 4:9]
Thank you scidam. it helped me

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  DataFrame: To print a column value which is not null out of 5 columns mani 2 144 Mar-18-2020, 06:07 AM
Last Post: mani
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 165 Mar-14-2020, 09:19 AM
Last Post: scidam
  Interate for loop over certain columns in dataframe Finpyth 2 146 Mar-06-2020, 08:34 AM
Last Post: Finpyth
  How to highlight dataframe columns SriRajesh 1 162 Feb-28-2020, 11:02 PM
Last Post: Marbelous
  Does the order of columns in the DataFrame matter? new_to_python 11 373 Feb-17-2020, 12:32 AM
Last Post: scidam
  Pandas dataframe columns collapsed in Spyder when printing UniKlixX 2 404 Nov-04-2019, 07:00 AM
Last Post: UniKlixX
  Selecting first and last row in python sudhirkaukuntla 2 267 Oct-01-2019, 06:12 AM
Last Post: sudhirkaukuntla
  How modify the DataFrame columns SriRajesh 2 329 Sep-12-2019, 03:14 PM
Last Post: SriRajesh
  Double 'for' loop and writing in a new columns dataframe marco_ita 0 324 Sep-07-2019, 12:44 PM
Last Post: marco_ita
  Creating A List of DataFrames & Manipulating Columns in Each DataFrame firebird 1 335 Jul-31-2019, 04:04 AM
Last Post: scidam

Forum Jump:

Users browsing this thread: 1 Guest(s)