Tag Archives: python for data analyst

Pandas Example – Write a Pandas program to find the row for where the value of a given column is maximum

(Python Example for Beginners)   Write a Pandas program to find the row for where the value of a given column is maximum.   Sample Solution: Python Code : import pandas as pd d = {‘col1’: [1, 2, 3, 4, 7], ‘col2’: [4, 5, 6, 9, 5], ‘col3’: [7, 8, 12, 1, 11]} df = …

Pandas Example – Write a Pandas program to get a list of a specified column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to get a list of a specified column of a DataFrame. Sample data: Powered by Original DataFrame col1 col2 col3 0 1 4 7 1 2 5 8 2 3 6 9 Col2 of the DataFrame to list: [4, 5, 6]   Sample Solution : Python …

Pandas Example – Write a Pandas program to convert DataFrame column type from string to datetime

(Python Example for Beginners)   Write a Pandas program to convert DataFrame column type from string to datetime. Sample data: String Date: 0 3/11/2000 1 3/12/2000 2 3/13/2000 dtype: object Original DataFrame (string to datetime): 0 0 2000-03-11 1 2000-03-12 2 2000-03-13   Sample Solution : Python Code : import pandas as pd import numpy as …

Pandas Example – Write a Pandas program to combining two series into a DataFrame

(Python Example for Beginners)   Write a Pandas program to combining two series into a DataFrame. Sample data: Data Series: 0 100 1 200 2 python 3 300.12 4 400 dtype: object 0 10 1 20 2 php 3 30.12 4 40 dtype: object New DataFrame combining two series: 0 1 0 100 10 1 …

Pandas Example – Write a Pandas program to reset index in a given DataFrame

(Python Example for Beginners)   Write a Pandas program to reset index in a given DataFrame. Sample data: Original DataFrame attempts name qualify score 0 1 Anastasia yes 12.5 1 3 Dima no 9.0 2 2 Katherine yes 16.5 3 3 James no NaN 4 2 Emily no 9.0 5 3 Michael yes 20.0 6 …

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 count the NaN values in one or more columns in DataFrame. Sample data: Original DataFrame attempts name qualify score 0 1 Anastasia yes 12.5 1 3 Dima no 9.0 2 2 Katherine yes 16.5 3 3 James no NaN 4 2 Emily no 9.0 5 …

Pandas Example – Write a Pandas program to change the order of a DataFrame columns

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

Pandas Example – Write a Pandas program to iterate over rows in a DataFrame

(Python Example for Beginners)   Write a Pandas program to iterate over rows in a DataFrame. Sample Python dictionary data and list labels: exam_data = [{‘name’:’Anastasia’, ‘score’:12.5}, {‘name’:’Dima’,’score’:9}, {‘name’:’Katherine’,’score’:16.5}]   Sample Solution : Python Code : import pandas as pd import numpy as np exam_data = [{‘name’:’Anastasia’, ‘score’:12.5}, {‘name’:’Dima’,’score’:9}, {‘name’:’Katherine’,’score’:16.5}] df = pd.DataFrame(exam_data) for index, row …

Pandas Example – Write a Pandas program to delete the ‘attempts’ column from the DataFrame

(Python Example for Beginners)   Write a Pandas program to delete the ‘attempts’ column from the 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, 2, 1], ‘qualify’: …

Pandas Example – Write a Pandas program to replace the ‘qualify’ column contains the values ‘yes’ and ‘no’ with True and False

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