pydatatable
by Selva Prabhakaran | Posted on August 31, 2019
101 Python datatable Exercises (pydatatable)
1. How to import datatable package and check the version?
Difficulty Level: L1
You need to import datatable as dt
for the rest of the codes in this exercise to work.
2. How to create a datatable Frame from a list, numpy array, pandas dataframe?
Difficulty Level: L1
Question: Create a datatable Frame from a list, numpy array and pandas dataframe.
Input:
Desired Output:
3. How to import csv file as a pydatatable Frame?
Difficulty Level: L1
Question: Read files as datatable Frame.Show Solution
Input: BostonHousing dataset
4. How to read first 5 rows of pydatatable Frame ?
Difficulty Level: L1
Question: Read first 5
rows of datatable Frame.
Input URL for CSV file: https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv
5. How to add new column in pydatatable Frame from a list?
Difficulty Level: L1
Question: Read first 5
rows of datatable Frame and add a new column of length 5
.
Input URL for CSV file: https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv
6. How to do addition of existing columns to get a new column in pydatatable Frame?
Difficulty Level: L1
Question: Add age
and rad
columns to get a new column in datatable Frame.
Input: BostonHousing dataset
7. How to get the int value of a float column in a pydatatable Frame?
Difficulty Level: L1
Question: Get the int value of a float column dis
in datatable Frame.
Input: BostonHousing datasetShow Solution
8. How to create a new column based on a condition in a datatable Frame?
Difficulty Level: L2
Question: Create a new column having value as ‘Old’ if age greater than 60 else ‘New’ in a `datatable` Frame.
Input: BostonHousing datasetShow Solution
9. How to left join two datatable Frames?
Difficulty Level: L1
Question: join two Frames.
Input:
Primary Key : AShow Solution
10. How to rename a column in a pydatatable Frame?
Difficulty Level: L1
Question: Rename column zn
to zn_new
in a datatable Frame.
Input: BostonHousing dataset
11. How to import every 50th row from a csv file to create a datatable Frame?
Difficiulty Level: L2
Question: Import every 50th row of [BostonHousing dataset] (BostonHousing.csv) as a dataframe.
Input: BostonHousing dataset
12. How to change column values when importing csv to a Python datatable Frame?
Difficulty Level: L2
Question: Import the boston housing dataset, but while importing change the 'medv'
(median house value) column so that values < 25 becomes ‘Low’ and > 25 becomes ‘High’.
Input: BostonHousing datasetShow Solution
13. How to change value at particular row and column in a Python datatable Frame?
Difficulty Level: L1
Question: Change value at row number 2 and column number 1 as 5
in a datatable Frame.
Input: BostonHousing dataset
14. How to delete specific cell, row, column, row per condition in a datatable Frame?
Difficulty Level: 2
Questions:
Delete the cell at position
2,1
.Delete the
3rd
row.Delete the
chas
column.Delete rows where column
zn
is having 0 value.
Input: BostonHousing dataset
15. How to convert datatable Frame to pandas, numpy, dictionary, list, tuples, csv files?
Difficulty Level: L1
Question: Convert datatable Frame to pandas, numpy, dictionary, list, tuples, csv files.
Input: BostonHousing dataset
16. How to get data types of all the columns in the datatable Frame?
Difficulty Level: L1
Question: Get data types of all the columns in the datatable Frame.
Input: BostonHousing dataset
Desired Output:
Show Solution
17. How to get summary stats of each column in datatable Frame?
Difficulty Level: L1
Questions:
For each column:
Get the sum of the column values.
Get the max of the column values.
Get the min of the column values.
Get the mean of the column values.
Get the standard deviation of the column values.
Get the mode of the column values.
Get the modal value of the column values.
Get the number of unique values in column.
Input: BostonHousing dataset
18. How to get the column stats of particular column of the datatable Frame?
Difficulty Level: L1
Question: Get the max value of zn
column of the datatable Frame
Input: BostonHousing dataset
Desired Output: 100
19. How to apply group by functions in datatable Frame?
Difficulty Level: L1
Question: Find the mean price for every manufacturer using Cars93 dataset.
Input: Cars93
Desired Output:
20. How to arrange datatabe Frame in ascending order by column value?
Difficulty Level: L1
Question: Arrange datatable Frame in ascending order by Price
.
Input: Cars93
Desired Output:
21. How to arrange datatabe Frame in descending order by column value?
Difficulty Level: L1
Question: Arrange datatable Frame in descending order by Price
.
Input: Cars93
Desired Output:
22. How to repeat(append) the same data in datatable Frame?
Difficulty Level: L1
Question: Repeat(append) the same data 5 times in datatable Frame.
Input: Cars93Show Solution
23. How to replace string with another string in entire datatable Frame?
Difficulty Level: L1
Question: Replace Audi
with My Dream Car
in entire datatable Frame.
Input: Cars93Show Solution
24. How to extract the details of a particular cell with given criterion??
Difficulty Level: L1
Question: Extract which manufacturer, model and type has the highest Price
.
Input: Cars93
Desired Output:
Show Solution
25. How to rename a specific columns in a dataframe?
Difficulty Level: L2
Question: Rename the column Model
as Car Model
.
Input: Cars93Show Solution
26. How to count NA values in every column of a datatable Frame?
Difficulty Level: L1
Question: Count NA values in every column of a datatable Frame.
Input: Cars93
Desired Output:
Show Solution
27. How to get a specific column from a datatable Frame as a datatable Frame instead of a series?
Difficulty Level: L1
Question :Get the column (Model
) in datatable Frame as a datatable Frame (rather than as a Series).
28. How to reverse the order of columns of a datatable Frame?
Difficulty Level: L1
Question : Reverse the order of columns in Cars93
datatable Frame.
Input: Cars93Show Solution
29. How to format or suppress scientific notations in Python datatable Frame?
Difficulty Level: L2
Question: Suppress scientific notations like ‘e-03’ in df
and print upto 6 numbers after decimal.
Input
Desired Output
30. How to filter every nth row in a pydatatable?
Difficulty Level: L1
Question: From df
, filter the 'Manufacturer'
, 'Model'
and 'Type'
for every 20th row starting from 1st (row 0).
Input: Cars93Show Solution
31. How to reverse the rows of a python datatable Frame?
Difficulty Level: L2
Question: Reverse all the rows.
Input: Cars93Show Solution
32. How to find out which column contains the highest number of row-wise maximum values?
Difficulty Level: L2
Question: What is the column name with the highest number of row-wise maximum’s.
Input: BostonHousing dataset
Desired Output:
tax
Show Solution
33. How to normalize all columns in a dataframe?
Difficulty Level: L2
Questions:
Normalize all columns of
df
by subtracting the column mean and divide by standard deviation.Range all columns of
df
such that the minimum value in each column is 0 and max is 1.
Don’t use external packages like sklearn.
Input: BostonHousing dataset
Desired Output:
34. How to compute grouped mean on datatable Frame and keep the grouped column as another column?
Difficulty Level: L1
Question: In df
, Compute the mean price
of every fruit
, while keeping the fruit
as another column instead of an index.
Input
Desired Output:
Show Solution
35. How to join two datatable Frames by 2 columns?
Difficulty Level: L2
Question: Join dataframes df1
and df2
by ‘A’ and ‘B’.
Input
Desired Output:
Show Solution
36. How to create leads (column shifted up by 1 row) of a column in a datatable Frame?
Difficulty Level: L2
Question: Create new column in df
, which is a lead1 (shift column A
up by 1 row).
Input:
Desired Output:
Machine Learning Exercise
36. How to use FTRL Model to calculate the probability of a person having diabetes?
Difficulty Level: L3
Question 1: Use Follow the Regularized Leader (Ftrl
) Model to calculate the probability of a person having diabetes.
Question 2: Find the feature importance of the features used in model.
Input:
Training Data : pima_indian_diabetes_training_data.csv
Testing Data : pima_indian_diabetes_testing_data.csvShow Solution
Author: Ajay Kumar
Reference : https://www.machinelearningplus.com/data-manipulation/101-python-datatable-exercises-pydatatable/
Last updated