Pandas Practice Set-1: Select a series from a DataFrame and print
3. Select a Series from Diamonds DataFrame
Write a Pandas program to select a series from diamonds DataFrame. Print the content of the series.
Sample Solution :
Python Code :
import pandas as pd
diamonds = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/diamonds.csv')
print(diamonds['carat'])
Sample Output:
runfile('C:/Users/User/.spyder-py3/temp.py', wdir='C:/Users/User/.spyder-py3') 0 0.23 1 0.21 2 0.23 3 0.29 4 0.31 5 0.24 6 0.24 7 0.26 8 0.22 9 0.23 10 0.30 11 0.23 12 0.22 13 0.31 14 0.20 15 0.32 16 0.30 17 0.30 18 0.30 19 0.30 20 0.30 21 0.23 22 0.23 23 0.31 24 0.31 25 0.23 26 0.24 27 0.30 28 0.23 29 0.23 53910 0.70 53911 0.57 53912 0.61 53913 0.80 53914 0.84 53915 0.77 53916 0.74 53917 0.90 53918 0.76 53919 0.76 53920 0.70 53921 0.70 53922 0.70 53923 0.73 53924 0.73 53925 0.79 53926 0.71 53927 0.79 53928 0.79 53929 0.71 53930 0.71 53931 0.71 53932 0.70 53933 0.70 53934 0.72 53935 0.72 53936 0.72 53937 0.70 53938 0.86 53939 0.75 Name: carat, Length: 53940, dtype: float64
For more Practice: Solve these Related Problems:
- Write a Pandas program to extract the 'price' column from the diamonds DataFrame and display its head.
- Write a Pandas program to select the 'cut' series from the diamonds DataFrame and print the unique values.
- Write a Pandas program to extract a series for 'carat' from the diamonds DataFrame and compute its descriptive statistics.
- Write a Pandas program to select a series (e.g., 'color') from the diamonds DataFrame and plot its value counts.
Go to:
PREV : Modify Default Column Values and Print First 6 Rows.
NEXT : Create a New 'Quality -color' Series.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?