Tag Archives: python for business analysts

Pandas Example – Write a Pandas program to filter words from a given series that contain atleast two vowels

(Python Example for Beginners)   Write a Pandas program to insert a new column in existing DataFrame. Sample DataFrame: Sample Python dictionary data and list labels: 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, …

Pandas Example – Write a Pandas program to append a new row ‘k’ to DataFrame with given values for each column. Now delete the new row and return the original data frame

(Python Example for Beginners)   Write a Pandas program to append a new row ‘k’ to DataFrame with given values for each column. Now delete the new row and return the original 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, …

Pandas Example – Write a Pandas program to calculate the mean score for each different student in data frame

(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, …

Pandas Example – Write a Pandas program to count the number of rows and columns of a DataFrame

(Python Example for Beginners)   Write a Pandas program to count the number of rows and columns of a DataFrame. 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, …

Pandas Example – Write a Pandas program to display a summary of the basic information about a specified DataFrame and its data

(Python Example for Beginners)   Write a Pandas program to display a summary of the basic information about a specified DataFrame and its data. 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, …

Pandas Example – Write a Pandas program to check the equality of two given series

(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) …

Pandas Example – Write a Pandas program to create a TimeSeries to display all the Sundays of given year.

(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 …

Pandas Example – Write a Pandas program to compute difference of differences between consecutive numbers of a given series

(Python Example for Beginners)   Write a Pandas program to compute difference of differences between consecutive numbers of a given series.   Sample Solution : Python Code : import pandas as pd series1 = pd.Series([1, 3, 5, 8, 10, 11, 15]) print(“Original Series:”) print(series1) print(“nDifference of differences between consecutive numbers of the said series:”) print(series1.diff().tolist()) print(series1.diff().diff().tolist()) …

Pandas Example – Write a Pandas program to calculate the number of characters in each word in a given series

(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 …

Pandas Example – Write a Pandas program to calculate the frequency counts of each unique value of a given series

(Python Example for Beginners)   Write a Pandas program to calculate the frequency counts of each unique value of a given series.   Sample Solution : Python Code : import pandas as pd import numpy as np num_series = pd.Series(np.take(list(‘0123456789’), np.random.randint(10, size=40))) print(“Original Series:”) print(num_series) print(“Frequency of each unique value of the said series.”) result = …