Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print sample set of columns from dataframe in Pandas? [duplicate]

How do you print (in the terminal) a subset of columns from a pandas dataframe?

I don't want to remove any columns from the dataframe; I just want to see a few columns in the terminal to get an idea of how the data is pulling through.

Right now, I have print(df2.head(10)) which prints the first 10 rows of the dataframe, but how to I choose a few columns to print? Can you choose columns by their indexed number and/or name?

like image 877
daniellemarie Avatar asked Aug 08 '17 20:08

daniellemarie


Video Answer


1 Answers

print(df2[['col1', 'col2', 'col3']].head(10)) will select the top 10 rows from columns 'col1', 'col2', and 'col3' from the dataframe without modifying the dataframe.

like image 180
RagingRoosevelt Avatar answered Oct 18 '22 11:10

RagingRoosevelt