w3resource

Pandas: Get the columns of the DataFrame


1. Getting DataFrame Columns

Write a Pandas program to get the columns of the DataFrame (movies_metadata.csv file).

Sample Solution:

Python Code:

import pandas as pd
import numpy as np
df = pd.read_csv('movies_metadata.csv')
print("Columns of the DataFrame:")
print(df.columns)

Sample Output:

Columns of the DataFrame:
Index(['adult', 'belongs_to_collection', 'budget', 'genres', 'homepage', 'id',
       'imdb_id', 'original_language', 'original_title', 'overview',
       'popularity', 'poster_path', 'production_companies',
       'production_countries', 'release_date', 'revenue', 'runtime',
       'spoken_languages', 'status', 'tagline', 'title', 'video',
       'vote_average', 'vote_count'],
      dtype='object')

For more Practice: Solve these Related Problems:

  • Write a Pandas program to load movies_metadata.csv and list all column names in alphabetical order.
  • Write a Pandas program to load movies_metadata.csv and display column names along with their data types.
  • Write a Pandas program to extract the column names from movies_metadata.csv and save them as a Python list.
  • Write a Pandas program to load movies_metadata.csv and print column names that contain the substring "date".

Python-Pandas Code Editor:

Sample Table:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Python Pandas Data Series, DataFrame Exercises Home.
Next: Write a Pandas program to get the information of the DataFrame (movies_metadata.csv file)including data types and memory usage.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.