(Python Example for Beginners) Write a Pandas program to change the order of a DataFrame columns. Sample data: Original DataFrame col1 col2 col3 0 1 4 7 1 4 5 8 2 3 6 9 3 4 7 0 4 5 8 1 After altering col1 and col3 col3 col2 col1 0 7 4 …
(Python Example for Beginners) Write a Pandas program to rename columns of a given DataFrame. Sample data: Original DataFrame col1 col2 col3 0 1 4 7 1 2 5 8 2 3 6 9 New DataFrame after renaming columns: Column1 Column2 Column3 0 1 4 7 1 2 5 8 2 3 6 9 …
(Python Example for Beginners) Write a Pandas program to replace the ‘qualify’ column contains the values ‘yes’ and ‘no’ with True and False. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, …
(Python Example for Beginners) Write a Pandas program to calculate the mean score for each different student in data frame. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, 2, 3, 1, …
(Python Example for Beginners) Write a Pandas program to calculate the sum of the examination attempts by the students. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, 2, 3, 1, 1, …
(Python Example for Beginners) Write a Pandas program to select the rows where the number of attempts in the examination is greater than 2. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, …
(Python Example for Beginners) Write a Pandas program to check the equality of two given series. Sample Solution : Python Code : import pandas as pd nums1 = pd.Series([1, 8, 7, 5, 6, 5, 3, 4, 7, 1]) nums2 = pd.Series([1, 8, 7, 5, 6, 5, 3, 4, 7, 1]) print(“Original Series:”) print(nums1) print(nums2) …
(Python Example for Beginners) Write a Pandas program to convert given series into a dataframe with its index as another column on the dataframe. Sample Solution : Python Code : import numpy as np import pandas as pd char_list = list(‘ABCDEFGHIJKLMNOP’) num_arra = np.arange(8) num_dict = dict(zip(char_list, num_arra)) num_ser = pd.Series(num_dict) df = num_ser.to_frame().reset_index() …
(Python Example for Beginners) Write a Pandas program to create a TimeSeries to display all the Sundays of given year. Sample Solution : Python Code : import pandas as pd result = pd.Series(pd.date_range(‘2020-01-01′, periods=52, freq=’W-SUN’)) print(“All Sundays of 2019:”) print(result) Sample Output: All Sundays of 2019: 0 2020-01-05 1 2020-01-12 2 2020-01-19 3 2020-01-26 …
(Python Example for Beginners) Write a Pandas program to calculate the number of characters in each word in a given series. Sample Solution : Python Code : import pandas as pd series1 = pd.Series([‘Php’, ‘Python’, ‘Java’, ‘C#’]) print(“Original Series:”) print(series1) result = series1.map(lambda x: len(x)) print(“nNumber of characters in each word in the said …