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
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']
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
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
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
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
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
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)