Column selection in pandas



First we want to create the dictionary. Next we want to convert the dictionary into dataframe by using pd.dataframe in the pandas concepts for that we want to import the pandas. Then we can select the column.








Example-1
import pandas as pd

l = {'Name' : ["Bill Gates", "Mark", "Warren", "Jeff Bezos"],
'Age':[ 10, 20, 30, 40]}

n = pd.DataFrame(l)

print(n[['Name']])



Output



         Name
0  Bill Gates
1        Mark
2      Warren
3  Jeff Bezos







Example-2
import pandas as pd

l={'Name' : ["Bill Gates", "Mark", "Warren", "Jeff Bezos"],
'Age':[ 10, 20, 30, 40]}

n = pd.DataFrame(l)

print(n[['Age']])



Output



Age
0   10
1   20
2   30
3   40