Pandas Practice Set-1: Select a series from a DataFrame and print
Pandas Practice Set-1: Exercise-3 with Solution
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
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to read a dataset of diamonds and modify the default columns values and print the first 6 rows.
Next: Write a Pandas program to create a new 'Quality –color' Series (use bracket notation to define the Series name) of the diamonds DataFrame.
What is the difficulty level of this exercise?
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://www.w3resource.com/python-exercises/pandas/practice-set1/pandas-practice-set1-exercise-3.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics