Selecting Few Columns from a dataframe - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Selecting Few Columns from a dataframe (/thread-16902.html) |
Selecting Few Columns from a dataframe - Shivi_Bhatia - Mar-19-2019 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 RE: Selecting Few Columns from a dataframe - scidam - Mar-20-2019 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] RE: Selecting Few Columns from a dataframe - Shivi_Bhatia - Mar-24-2019 Thank you scidam. it helped me |