w3resource

Pandas Practice Set-1: Display all column labels of diamonds DataFrame


20. Display All Column Labels

Write a Pandas program to display all column labels of diamonds DataFrame.

Sample Solution:

Python Code:

import pandas as pd
diamonds = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/diamonds.csv')
print("Column labels of diamonds DataFrame:")
print(diamonds.columns)

Sample Output:

Column labels of diamonds DataFrame:
Index(['carat', 'cut', 'color', 'clarity', 'depth', 'table', 'price', 'x', 'y',
       'z'],
      dtype='object')

For more Practice: Solve these Related Problems:

  • Write a Pandas program to print all column labels of the diamonds DataFrame in a single line.
  • Write a Pandas program to extract and display the column names as a list from the diamonds DataFrame.
  • Write a Pandas program to convert the DataFrame’s column labels to uppercase and then print them.
  • Write a Pandas program to display column labels along with their data types for the diamonds DataFrame.

Python Code Editor:

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

Previous: Write a pandas program to find the diamonds that are with a Fair or Good or Premium.
Next: Write a Pandas program to read only a subset of 3 rows from diamonds DataFrame.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.