0% found this document useful (0 votes)
158 views

Numpy - Pandas Assignment

The document provides example exercises for working with pandas and numpy. For pandas, the exercises include checking for missing values, replacing missing values with means, converting a dictionary to a dataframe, sorting a dataframe by column, and replacing missing characters. For numpy, the exercises include creating matrices and arrays, finding min/max values, replacing odd numbers, reshaping arrays, adding a value to all array elements, and extracting columns.

Uploaded by

Amro Omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views

Numpy - Pandas Assignment

The document provides example exercises for working with pandas and numpy. For pandas, the exercises include checking for missing values, replacing missing values with means, converting a dictionary to a dataframe, sorting a dataframe by column, and replacing missing characters. For numpy, the exercises include creating matrices and arrays, finding min/max values, replacing odd numbers, reshaping arrays, adding a value to all array elements, and extracting columns.

Uploaded by

Amro Omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pandas Exercises:

1) How to check if a dataframe has any missing values?


2) How to replace missing values of multiple numeric columns with the mean?
3) Given a dictionary, convert it into corresponding dataframe and display it
4) Given a dataframe, sort it by title columns
5) How to replace missing spaces in a string with the least frequent character?
Replace the spaces in my_str with the least frequent character.

Input:
# input
my_str = 'dbc deb abed ggade'

'''
Desired Output

'dbccdebcabedcggade' # least frequent is 'c'


'''

Output:
"\nDesired Output\n\n'dbccdebcabedcggade' # least frequent is 'c'\n"

Numpy Exercises:
1) Create a 3x3 matrix with values ranging from 0 to 8

2) Create a 10x10 array with random values and find the minimum and maximum values

3) Replace all odd numbers in the given array with -1

Start with:

exercise_1 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

Desired output:
[ 0, -1, 2, -1, 4, -1, 6, -1, 8, -1]

4) Convert a 1-D array into a 2-D array with 3 rows

Start with:

exercise_2 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8])

Desired output:

[[ 0, 1, 2]
[3, 4, 5]
[6, 7, 8]]

5) Add 202 to all the values in given array


Start with:

exercise_3 = np.arange(4).reshape(2,-1)

Desired output:

[[202, 203]
[204, 205]]

6) Extract the first four columns of this 2-D array


Start with this:

exercise_6 = np.arange(100).reshape(5,-1)

Desired output:

[[ 0 1 2 3]
[20 21 22 23]
[40 41 42 43]
[60 61 62 63]
[80 81 82 83]]

You might also like