w3resource

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

Pandas Practice Set-1: Exercise-20 with Solution

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')

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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/pandas/practice-set1/pandas-practice-set1-exercise-20.php