Python Exercise Lists

Python Pandas Data Series Exercises

1. Write a Python Pandas program to show a one dimensional array-like object contains the array in the following output.

The output is:

a = ['Python', 'Pandas', 'Free', 'Exercises', 'Solutions']

Expected Answer:
0 Python
1 Pandas
2 Free
3 Exercises
4 Solutions
dtype: object

Click for the answer



2. Write a Python Pandas program first to show a one dimensional array-like object contains the array in the following output. Therefore convert the type of pandas series to python list.

The output is:

a = ['Python', 'Pandas', 'Free', 'Exercises', 'Solutions']

Expected Answer:
Initial Pandas Series:
0 Python
1 Pandas
2 Free
3 Exercises
4 Solutions
dtype: object

Initial Pandas Type: [class 'pandas.core.series.Series']

Convert from Pandas Series to Python list
['Python', 'Pandas', 'Free', 'Exercises', 'Solutions']

Python Type: [class 'list']

Click for the answer



3. Write a Python Pandas program first to carry out the mathematics operations for the following two series a1 and a2. The mathematics operations are addition, subtraction, multiplication and division.

The output is:

a1 = [6, 6, 6, 6, 6]
a2 = [1, 2, 5, 7, 9]

Expected Answer:
Addition of two Series:
0 7
1 8
2 11
3 13
4 15
dtype: int64

Subtraction of two Series:
0 5
1 4
2 1
3 -1
4 -3
dtype: int64

Multiplication of two Series:
0 6
1 12
2 30
3 42
4 54
dtype: int64

Division of Series1 by Series2:
0 6.000000
1 3.000000
2 1.200000
3 0.857143
4 0.666667
dtype: float64

Click for the answer



4. Write a Numpy program first to show the numpy array in the following a1, then convert the numpy array to pandas series.

The output is:

a1 = ['Python', 'Pandas', 'Free', 'Exercises', 'Solutions']

Expected Answer:
NumPy array:
['Python' 'Pandas' 'Free' 'Exercises' 'Solutions']

Converted to Pandas series:
0 Python
1 Pandas
2 Free
3 Exercises
4 Solutions
dtype: object

Click for the answer



5. Write a Numpy program first to show the numpy array in the following a1, then convert the numpy array to pandas series.

The output is:

student_marks = {'Python': 100, 'Machine Learning': 83, 'Big Data Management':78, 'Data Science':90}

Expected Answer:
Initial dictionary:
{'Python': 100, 'Machine Learning': 83, 'Big Data Management': 78, 'Data Science': 90}

From python library converted to pandas series:
Python        100
Machine Learning   83
Big Data Management 78
Data Science     90
dtype: int64

Click for the answer



6. Write a Pandas program to show the pandas series with a1 and a2 content. Therefore compare the equality of two elements.

The output is:

a1 = ['Python', 'Pandas', 'Free', 'Exercises', 'Solutions']
a2 = ['Python', 'Numpy', 'Free', 'Answers', 'Solutions']

Expected Answer:
Pandas Series 1:
0 Python
1 Pandas
2 Free
3 Exercises
4 Solutions
dtype: object

Pandas Series 2:
0 Python
1 Numpy
2 Free
3 Answers
4 Solutions
dtype: object

Compare the equality of Pandas Series 1 and 2:
0 True
1 False
2 True
3 False
4 True
dtype: bool

Click for the answer



7. Write a Pandas program to show the pandas series with a1 content. Therefore change the whole a1 data series to numeric.

The output is:

a1 = ['100', '200', 'pandas', '300', 'exercises', '600']

Expected Answer:
Initial Data Series:
0 100
1 200
2 pandas
3 300
4 exercises
5 600
dtype: object

Change to numeric Data Series:
0 100.0
1 200.0
2 NaN
3 300.0
4 NaN
5 600.0
dtype: float64

Click for the answer



                               


More Exercises:

Python String Exercises
Python List Exercises
Python Library Exercises
Python Sets Exercises
Python Array Exercises
Python Condition Statement Exercises
Python Lambda Exercises
Python Function Exercises
Python File Input Output Exercises
Python Tkinter Exercises


More Numpy Exercises:

Numpy String Exercises
Numpy Integer Exercises
Numpy Array Exercises
Numpy Data Analysis Exercises
Numpy Data Sorting Exercises


More Pandas Exercises:

Pandas Series Exercises


More Tutorials:

Python Installation - Linux (Ubuntu)
Python Installation - Mac OS
Integrated Development Environment - IDE
Python - Basic Variables
Python - Sequence Introduction
Python - Output Formatting
Python - Escape Character
Python - Type Conversion
Python - Numbers
Python – Arithmetic Operators
Python – Assignment Operators
Python – Comparison Operators
Python – Logical Operators
Python – Precedence and Associativity Operators
Python – Bytes Type and Usage
Python – Long & Raw Strings
Python – Concatenate Function
Python – Slice Function
Python – Length and Split Function
Python – Join and Count Function
Python – Find Function
Python – Index Function
Python – Alignment Function
Python – Startswith and Endswith Function
Python – String Case Conversion
Python – Remove Specified Character
Python – Encode and Decode Function
Python – dir and help Function
Python – Input Output Introduction
Python – Basic Operation
Python – Open Function
Python – Read Function
Python – Readline Function
Python – Write Function
Python – Close Function
Python – Seek and Tell Function
Python – Pickle Module
Python - File Input Module and Linecache Module
Python - Pathlib Module
Python - Pathlib Module
Python - os.path Module
Python - fnmatch Module
Python - Tuple Introduction
Python - List Introduction
Python - List Add Element
Python - List Delete Element
Python - List Modification Element
Python - List Find Element
Python - Dictionary Introduction
Python - Dictionary Basic Operation
Python - Dictionary Method Guide
Python - Set Collection
Python - Set Basic Operation
Python - Set Basic Method
Python - Frozenset Method
Python - If Condition I
Python - If Condition II
Python - While loop
Python - For loop
Python - Pass Statement
Python - Break Statement
Python - Zip Reverse Function
Python - Function Introduction
Python - Positional Parameters
Python - Key Arguments
Python - None and Return
Python - Variable Scope
Python - Local Function
Python - Closure Method
Python - Lamdba Expression