In this python pandas program, we will print the selected columns from DataFrame using the pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create a dataframe using pd.DataFrame().
- Print the selected columns from DataFrame using df[[‘Name’,’Age’]].
- Print the output.
				
					import pandas as pd
d = {'Sr.no.':[1,2,3],'Name':['Alex','John','Peter'],'Age':[30,27,29]}
df = pd.DataFrame(d)
print("Original dataframe: \n",df)
print(df[['Name','Age']]) 
				
			
		Output :
				
					Original dataframe: 
    Sr.no.   Name  Age
0       1   Alex   30
1       2   John   27
2       3  Peter   29
    Name  Age
0   Alex   30
1   John   27
2  Peter   29