Docsity

WGU D206 - Data Cleaning - Lesson 3 Python Labs, Exams of Data Acquisition

Toggle sidebar
bg1
WGU D206 - Data Cleaning - Lesson 3
Python Labs
Import the dataset Boston_housing_data.csv with the locationid column being an integer. Use print() to
see the dataset as output. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64})
data = df.head(5)
print(data)
Displays the number of rows and columns in the dataframe stored as df. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64})
print(df.shape)
Display the column names in the dataframe stored as df. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64})
print(list(df.columns.values))
Display the mean, count, min, and max of all the numeric data using a single line of code in the
dataframe stored as df. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) data =
df.describe() print(data)
Display the variable type of each column in the dataframe stored as df. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64})
print (df.dtypes)
Display unique values in the locationzone column in dataframe stored as df. - โœ”โœ”
df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64})
uniqueValues = df['locationzone'].unique()
print('Unique elements in column "locationzone" ') print(uniqueValues)
pf3

Partial preview of the text

Download WGU D206 - Data Cleaning - Lesson 3 Python Labs and more Exams Data Acquisition in PDF only on Docsity!

WGU D206 - Data Cleaning - Lesson 3

Python Labs

Import the dataset Boston_housing_data.csv with the locationid column being an integer. Use print() to see the dataset as output. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) data = df.head(5) print(data) Displays the number of rows and columns in the dataframe stored as df. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) print(df.shape) Display the column names in the dataframe stored as df. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) print(list(df.columns.values)) Display the mean, count, min, and max of all the numeric data using a single line of code in the dataframe stored as df. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) data = df.describe() print(data) Display the variable type of each column in the dataframe stored as df. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) print (df.dtypes) Display unique values in the locationzone column in dataframe stored as df. - โœ”โœ” df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) uniqueValues = df['locationzone'].unique() print('Unique elements in column "locationzone" ') print(uniqueValues)

Display the unique values in the locationzone column and the number of times each value appears in the dataframe stored as df. - โœ”โœ”df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) data = df['locationzone'].value_counts() print(data) Import the data set Boston_housing_data_clean.csv with the locationid column being an integer. Use print() to see the data set as output. - โœ”โœ”df = pd.read_csv('/home/ucertify/Boston_housing_data_clean.csv',dtype={'locationid':np.int64}) print(df) Display any duplicate rows in the dataframe stored as df. - โœ”โœ”df = pd.read_csv('/home/ucertify/Boston_housing_data.csv',dtype={'locationid':np.int64}) duplicatedRows = df.loc[df.duplicated()] print('Duplicated rows in "Boston_housing_data_clean" ') print(duplicatedRows) Ensure there are no missing observations in the dataframe stored as df. - โœ”โœ”df = pd.read_csv('/home/ucertify/Boston_housing_data_clean.csv',dtype={'locationid':np.int64}) data = df.isnull().sum() print(data) Display the mean value of the medv column per district on March 27, 2016. To do this, limit the dataset to observations that were appraised on March 27, 2016, and create a datasheet that aggregates all the data by the locationdistrict column and displays the mean of medv rounded off to one decimal place. - โœ”โœ”df = pd.read_csv('/home/ucertify/Boston_housing_data_clean.csv',dtype={'locationid':np.int64}) df2 = df.loc[df['date_appraised'] == '2016- 03 - 27'] df3 = df2.groupby('locationdistrict' ['medv'].mean().round(1) print(df3) Import the dataset iris.csv and display the first five rows. - โœ”โœ”df = pd.read_csv('/home/ucertify/iris.csv') print (df.head())