Python Forum
Selecting Few Columns from a dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting Few Columns from a dataframe
#1
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)
skip_rows.head(4)]
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
Reply
#2
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]
Reply
#3
Thank you scidam. it helped me
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add columns to polars dataframe sayyedkamran 1 1,684 Nov-03-2023, 03:01 PM
Last Post: gulshan212
  concat 3 columns of dataframe to one column flash77 2 776 Oct-03-2023, 09:29 PM
Last Post: flash77
  Convert several columns to int in dataframe Krayna 2 2,361 May-21-2021, 08:55 AM
Last Post: Krayna
  Outputs "NaN" after "DataFrame columns" function? epsilon 7 3,571 Jan-27-2021, 10:59 AM
Last Post: epsilon
  Adapting a dataframe to the some of columns flyway 2 2,032 Aug-12-2020, 07:21 AM
Last Post: flyway
  Difference of two columns in Pandas dataframe zinho 2 3,312 Jun-17-2020, 03:36 PM
Last Post: zinho
  DataFrame: To print a column value which is not null out of 5 columns mani 2 2,073 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 2,412 Mar-14-2020, 09:19 AM
Last Post: scidam
  Interate for loop over certain columns in dataframe Finpyth 2 1,915 Mar-06-2020, 08:34 AM
Last Post: Finpyth
  How to highlight dataframe columns SriRajesh 1 1,822 Feb-28-2020, 11:02 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020