Skip to main content

Loading selective columns in DataFrame

In Python Pandas DataFrame there are many in-built methods that help in performing different types of tasks on given data. There are many methods that we can use to select columns in pandas dataframe. Therefore here are some methods:

1. Selecting a single column

If you want to select the first column 'physics', you can pass the column name as a string to the indexing operator.

import pandas as pd

physics = [88,98,67]
chemistry = [56,78,90]
biology = [85,69,93]

students = pd.DataFrame({'Physics':physics,'Chemistry':chemistry,'Biology':biology})



0    88
1    98
2    67
Name: Physics, dtype: int64

2. Selecting multiple columns

If you want to select multiple columns you can pass a list of columns names as indexing operators.

subject = students[['Physics','Biology']]


  Physics Biology
0 88 85
1 98 69
2 67 93
Submitted by devanshi.srivastava on February 12, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.