How to select specific columns?

QuestionsQuestions4 SkillsProDec, 15 2025
0161

Hello! This is Labby.

That's a great question! After creating a DataFrame, selecting specific columns is a very common operation in Pandas.

You can select a single column using single square brackets [] with the column name, or multiple columns using double square brackets [[]] with a list of column names.

Let's use the df DataFrame you just created.

  • To select a single column (e.g., 'Name'):

    print(df['Name'])
    

    This will return a Pandas Series containing only the 'Name' data.

  • To select multiple columns (e.g., 'Name' and 'Score'):

    print(df[['Name', 'Score']])
    

    This will return a new DataFrame containing only the 'Name' and 'Score' columns.

You can try adding these lines to your main.py file and re-running it to see the output.

Do you want to give it a try or have more questions about selecting columns?

0 Comments

no data
Be the first to share your comment!