cheatsheet from DataCamp.pdf

RamanKulkarni3 679 views 10 slides Jun 14, 2023
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

fbvtghbgfdregtrgdvfgrfbgf gbfcfergdfvdfbtfbdfgrthtrgrrgrtgrtgsdgrtgerger


Slide Content

>Cells and ranges
Specifying cell locations with column letter, row number format
=B2 Here we refer to the cell in column B, row 2.
Specifying absolute cell references with $ prefixes
The $ symbol before the column letter and/or row number tells Excel that the reference is absolute and should not change when the
formula is copied or moved to another cell. The following examples all specify column B, row 2.
=$B$2
=$B2
=B$2
Column and row references are both absolute
Column reference is absolute, row reference is relative
Column reference is relative, row reference is absolute
Specifying ranges with the start:end format
The start:end format is a convenient way to specify a range of cells in a formula.
Here is an example of start:end format when using the SUM() formula:
=SUM(B2:B5)
>Operators
Arithmetic operators
? =A2 + A3
? =A4 - B4
? =A6 * B1
? =C3 / B4
? =C5%
? =B1 ^ C1
Add two values with +. This example returns 3 + 6 = ,
Subtract a value from another with -.This example returns 10 - 7 =
Multiply two values with *. This example returns 21 * 2 = 4'
Divide two values with /. This example returns 28 / 7 = a
Convert a value to a percentage with %. This example returns 3.2r
Raise a value to power with ^. This example returns 2 ^ 6 = 64
Numeric comparison operators
Test for equality with =
=A1 = B1
=A2 = B2
Returns 1 = 2 which is FALSE
Returns 3 = 3 which is TRUE
Test for inequality with <>
=A1 < > B1
=A2 < > B2
Returns 1 < > 2 which is TRUE
Returns 3 < > 3 which is FALSE
Test greater than with >
=A3 > = B3
=A2 > B2
Returns 5 > 5 which is TRUE
Returns 3 > 3 which is FALSE
Test greater than or equal to with >=
=A3 > = B3
=A2 > B2
Returns 6 > =5 which is TRUE
Returns 3 > = 3 which is TRUE
Test less than with <
=A1 < B1
=A2 < B2
Returns 1 < 2 which is TRUE
Returns 3 < 3 which is FALSE
Test less than or equal to with <=
=A1 < = B1
=A2 < = B2
Returns 1 < = 2 which is TRUE
Returns 3 < = 3 which is TRUE
Use multiple logical conditions to determine the return value with IFS()
=IFS(cond1, return1, cond2, return2)
=IFS(A1 > B1, "1st", A2 > B2, "2nd", A3 > B3, "3rd") Returns "3rd"
Similar to IF(), but allowing multiple pairs of logical conditions and return values. If the first condition, cond1, is TRUE then the
function returns the first return value, return1. If the second condition, cond2 is TRUE, the function returns the second return value;
and so on.
Provide a default value in case of errors with IFERROR()
=IFERROR(value, value_if_error)
=IFERROR(A5 / A5, 1) Division of two missing values gives an error; this returns 1
If the first input does not result in an error then it is returned. If it does result in an error, the second input is returned.
Choose a return value based on a table of inputs with SWITCH()
=SWITCH(value, choice1, return1, choice2, return2, ...)
=SWITCH(MID(D3, 1, 5), "World", "planet", "Solar", "planetary system", "Milky", "galaxy", "Local",
"galaxy group") Returns "galaxy"
Takes a value as its first argument, followed by pairs of choices and return values. If the value matches the first choice, the function
returns the first return value; if the value matches the second choice, the function returns the second return value; and so on. If no
values match, the function returns an error.
>Flow control
Use a logical condition to determine the return value with IF()
=IF(cond, return_if_true, return_if_false)
=IF(ISBLANK(A5), "A5 is blank", "A5 is not blank") Returns "A5 is blank"
Takes a logical condition, cond, as its first argument. If cond is TRUE, IF() returns the value specified in the second argument
(return_if_true); if cond is TRUE, IF() returns the value specified in the third argument (return_if_false).
>Text functions and operators
Basics
=LEN(D5) Returns the length of a string in characters. This example returns 28.
Combining and splitting strings
? ="Hello " & D1 & "!"
? =REPT(D6, 3)
? =TEXTSPLIT(D4, "o")
? =TEXTSPLIT(D5, {"a","u"})
Returns "Hello World!?
Repeats text. This example returns "UniverseUniverseUniverse?
Splits a string on a delimiter. This example returns "L", "cal Gr", "up" in 3 cells: "Local Group"
split on the letter "o?
Splits a string on a delimiter. This example returns "L", "ni", "ke", "S", "percl",
"ster" in 6 cells: "Laniakea Supercluster" split on the letter "a" or the letter "u".
Mutating strings
? =MID(text, start, [length])
? =UPPER(text)
? =LOWER(text)
? =PROPER(text)
Extracts a substring starting at the position specified in the second argument and with the
length specified in the third argument. For example =MID(D6, 4, 5) Returns "verse?
Converts the text to uppercase. For example =UPPER(D3) Returns "MILKY WAY?
Converts the text to lowercase. For example =LOWER(D3) Returns "milky way?
Converts the text to title case. For example =PROPER("milky way") Returns "Milky Way"
>Data manipulation
? =FILTER(A1:B6, C1:C6>100)
? =SORT(A1:E6, 4)
? =SORTBY(A1:E6, D1:D6)
? =UNIQUE(A1:A6)
? =SEQUENCE(5, 1, 3, 2)
Gets a subset of the cell range in the first input that meets the condition in the second input?
Returns the dataset with rows in alphabetical order of the fourth column. Sorts the rows of the data
according to values in specified columns?
Returns the same as the SORT() example. Alternate, more flexible, syntax for sorting. Rather than
specifying the column number, you specify an array to sort by?
Gets a list of unique values from the specified data?
Returns 5 rows and 1 column containing the values 3, 5, 7, 9, 11. Generates a sequence of numbers,
starting at the specified start value and with the specified step size.
>Example dataset
Throughout most of this cheat sheet, we’ll be using this dummy dataset of 5 columns and 6 rows.
- A B C D E
1 1 2 6 World 1/1/2023
2 3 3 21 Solar System 1/2/2023
3 6 5 28 Milky Way 1/3/2023
4 10 7 301 Local Group 1/4/2023
5 21 11 325 Laniakea Supercluster 1/5/2023
6 21 13 496 Universe 1/6/2023
>Definitions
This cheat sheet describes the behavior of the Microsoft 365 version of Excel, and slight differences exist between Excel versions.
Definitions
Spreadsheet: An application, like Microsoft Excel, where you can store data, perform calculations, and organize information.
Workbook: A file containing a collection of one or more worksheets.
Worksheet: A single page in a workbook. It is a grid of cells arranged in rows and columns.
Cell: A rectangular box in a worksheet that can store a data value, a formula, or other content.
Formula: A piece of code to perform a calculation. Formulas start with an equals sign (=), and contain functions, mathematical
operators, values, and cell references.
Cell reference: The location of a cell. The column is described with letters and the row is described with numbers. For example, the
cell in the 4th column, 7th row would be denoted D7.
Cell range: A group of adjacent cells in a worksheet. A cell range is typically referred to by its upper-left and lower-right cells, such
as A1:C3, referring to the cells in columns A, B, and C and rows 1 through 3. You can use cell ranges to perform calculations on
multiple cells at once or to apply formatting to a group of cells.
- A B C
1 Cell A1 Cell B1 Cell C1
2 Cell A2 Cell B2 Cell C1
3 Cell A3 Cell B3 Cell C3
>Getting help
You can get help by accessing the help menu
?? Open Microsoft Excel?
??Click on the "Help" menu at the top of the screen?
ÿIn the Help menu, you will see various options for getting help, including a search bar where you can enter keywords to search for
specific topics?
?? You can also click on the "Help" button to open the Help pane, where you can browse through various topics and find answers to
common questions.
How to add a comment to a cell
??Click on the cell where you want to add a comment?
?? Right-click or CTRL+click on the cell and select the "New Comment" option from the context menu. You can also click on the
Insert menu then "New Comment"?
ÿThis will open a small text box next to the cell, where you can type your comment?
?? Once you have entered your comment, click the green arrow button to save it.
>Logical functions
Logical NOT with NOT()
=NOT(A1 = B1)w
=NOT(A1 = B1)w
Returns NOT(1 = 2) which is TRUE
Returns NOT(2 = 2) which is FALSE
Logical AND with AND()
=AND(A1 > 10, B1 < 20)w
=AND(A1 < 2, B1 < 20)w
Returns AND(1 > 10, 2 < 20) which is FALSE
Returns AND(1 < 2, 2 < 20) which is TRUE
Logical OR with OR()
=OR(A1 > 10, B1 < 20)
=OR(A1 < 2, B1 < 20)
Returns OR(1 > 10, 2 < 20) which is TRUE
Returns OR(1 < 2, 2 < 20) which is TRUE
Logical XOR with XOR()
=XOR(A1 > 10, B1 < 20)
=XOR(A1 > 10, B1 > 20)
Returns XOR(1 > 10, 2 < 20) which is TRUE
Returns XOR(1 > 2, 2 > 20) which is FALSE
>Data types
? =ISNUMBER(A1)
? =ISTEXT(D1)
? =ISLOGICAL(A1)
? =ISLOGICAL(A1=A1)
? =N(E1)
? =N(D1)
? =VALUETOTEXT(A1)
? =TEXT(C6, "0.00E+0")
? =DATEVALUE("1/1/2022")
Checks if a cell is a number. Returns TRU8
Checks if a cell is a text. Returns TRU8
Checks if a cell is a boolean. Returns FALS8
Checks if a cell is a boolean. Returns TRU8
Converts to number. Returns 44927: the serial date - the date as a number, counting Dec 31st 1899 as $
Converts to number. Returns an error, since it’s not a numbe@
Convert to text. Returns "1
Convert to formatted text. Returns "4.96E+2
Convert text to serial. Returns 44927: the serial date
>Counting data
? =COUNT(A5:E5)
? =COUNTA(A5:E5)
? =COUNTBLANK(A5:E5)
Returns 3: the number of cells in the range containing numbers, dates and currencies?
Returns 4: the number of cells in the range that aren't emptq
Returns 1: the number of cells that are empty or contain the empty string ("")
>Math functions
? =LOG(100, 10)
? =EXP(2)
? =MAX(A1:A6, C1:C3, 12)
? =MIN(A1:A6, C1:C3, 12)
? =MAXA(A1:A6, C1:C3, FALSE)
? =MINA(A1:A6, C1:C3, FALSE)
? =SUM(A1:A6, C1:C3, 12)
? =AVERAGE(A1:A6, C1:C3, 12)
? =MEDIAN(A1:A6, C1:C3, 12)
? =PERCENTILE.INC(C1:C6, 0.25)
? =ROUND(PI(), 2)
? =CEILING(PI(), 0.1)
? =FLOOR(PI(), 0.1)
? =VAR.S(B1:B6)
? =STDEV.S(B1:B6)
Returns 2: the base 10 logarithm of 10?
Returns e ^ 2 = 7.39?
Returns 28: the largest value in all cell ranges or values inputte?
Returns 1: the smallest value in all cell ranges or values inputted?
Returns same as MAX(), except TRUE is valued at 1 and FALSE is valued at ?
Returns same as MIN(), except TRUE is valued at 1 and FALSE is valued at ?
Returns 108: the total of all cell ranges or values inputte?
Returns 12: the mean of all cell ranges or values inputte?
Returns 10: the median of all cell ranges or values inputte?
Returns 22.75: the 25th percentile of the cell rang?
Returns 3.14: pi rounded to 2 decimal place?
Returns 3.2: pi rounded upwards to the nearest 0.$
Returns 3.1: pi rounded downwards to the nearest 0.$
Returns 19.37: sample variance of the cell rang?
Returns 4.40: sample standard deviation of the cell range
Excel Basics Cheat Sheet
Learn Excel online at www.DataCamp.com
>Conditional computation
Get the number of cells that meet a condition with COUNTIF()
=COUNTIF(A1:A6, ">5")
=COUNTIF(D1:D6, "Milky Way")
Returns 3: the number of cells greater than 5, ignoring blanks
Returns 1: the number of cells equal to “Milky Way”
Calculate the total of cells meeting conditions with SUMIF() and SUMIFS()
=SUMIF(A1:A6, ">5")
=SUMIF(A1:A6, ">5", B1:B6)
=SUMIFS(B1:B6, A1:A6, ">5", D1:D6, "<>Local Group")
Returns 37: the sum of elements in A1 to A6 filtered with values greater than 5
Returns 25: the sum of elements in B1 to B6 corresponding to values in A1 to A6 that are greater
than 5
Returns 18: the sum of B1:B6 where A1:A6 is greater than 5 and
D1:D6 is not equal to "Local Group"
Calculate the mean of cells meeting conditions with AVERAGEIF() & AVERAGEIFS()
=AVERAGEIF(A1:A6, ">5")
=AVERAGEIF(A1:A6, ">5", B1:B6)
=AVERAGEIFS(B1:B6, A1:A6, ">5", D1:D6, "<>Local Group")
Returns 12.33: the mean of elements in A1 to A6 filtered with values greater than 8
Returns 8.33: the mean of elements in B1 to B6 corresponding to values in A1 to A6 that are
greater than 5
Returns 9: the mean of B1:B6 where A1:A6 is greater than 5
and D1:D6 is not equal to "Local Group"
Learn Excel Online at
www.DataCamp.com

What is SQL?
SQL stands for “structured query language”. It is a language used to query,
analyze, and manipulate data from databases. Today, SQL is one of the most
wa_oltubgo_urnnlguafu_frfem
SQL Basics Cheat Sheet
SQL for Data Science
Learn SQL online at www.DataCamp.com
>The different dialects of SQL
Although SQL languages all share a basic structure, some of the specific
commands and styles can differ slightly. Popular dialects include MySQL,
SQLite, SQL Server, Oracle SQL, and more. PostgreSQL is a good place to start
—since it’s close to standard SQL syntax and is easily adapted to other
_afloergem
>Sample Data
Throughout this cheat sheet, we’ll use the columns listed in this sample table of
airbnb_listings
airbnb_listings
id city country number_of_rooms year_listed
1 Paris France 5 2018
2 Tokyo Japan 2 2017
3 New York USA 2 2022
>Filtering Data
Filtering on numeric columns
fff fyd
airbnb_listingsd
number_of_rooms >= ;
SELECT
FROM
WHERE 3
1. Get all the listings where number_of_rooms is more or equal to 3
*
airbnb_listingsd
number_of_rooms > ;
SELECT
FROM
WHERE 3
2. Get all the listings where number_of_rooms is more than 3
*
airbnb_listingsd
number_of_rooms = ;
SELECT
FROM
WHERE 3
3. Get all the listings where number_of_rooms is exactly equal to 3
*
airbnb_listingsd
number_of_rooms <= ;
SELECT
FROM
WHERE 3
4. Get all the listings where number_of_rooms is lower or equal to 3
*
airbnb_listingsd
number_of_rooms < ;
SELECT
FROM
WHERE 3
5. Get all the listings where number_of_rooms is lower than 3
*
airbnb_listingsd
number_of_rooms ;
SELECT
FROM
WHERE BETWEEN AND3 6
6. Get all the listings with 3 to 6 rooms
>Querying tables
fff fyd
airbnb_listings;
SELECT
FROM
1. Get all the columns from a table
city
airbnb_listings;
SELECT
FROM
2. Return the city column from the table
city, year_listed
airbnb_listings;
SELECT
FROM
3. Get the city and year_listed columns from the table
id, cityd
airbnb_listingsd
number_of_rooms ;
SELECT
FROM
ORDER BY A SC
4. Get the listing id, city, ordered by the number_of_rooms in ascending order
id, city
airbnb_listingsd
number_of_rooms ;
SELECT
FROM
ORDER BY D ESC
5. Get the listing id, city, ordered by the number_of_rooms in descending order
fff fyd
airbnb_listings
;
SELECT
FROM
LIMIT5
6. Get the first 5 rows from the airbnb_listings table
cityd
airbnb_lisitings;
SELECT DISTINCT
FROM
7. Get a unique list of cities where there are listings
Filtering on text columns
*
airbnb_listingsd
city = ;
SELECT
FROM
WHERE ‘Paris’
7. Get all the listings that are based in ‘Paris’
*
airbnb_listingsd
country (‘USA’, ‘France’);
SELECT
FROM
WHERE IN
8. Get the listings based in the and in ‘USA’ ‘ France’
*
airbnb_listingsd
city city ;
SELECT
FROM
WHERE L IKE AND N OT LIKE‘j%’ ‘ %t’
9. Get all the listings where the city starts with and where the city does not end in ‘j’ ‘ t’
Filtering on multiple columns
*
airbnb_listingsd
city = number_of_rooms > ;
SELECT
FROM
WHERE AND‘Paris’ 3
10. Get all the listings in where n umber_of_rooms is bigger than 3`Paris`
*
airbnb_listingsd
city = year_listed > ;
SELECT
FROM
WHERE OR ‘Paris’ 2012
11. Get all the listings in OR the ones that were listed after 2012`Paris`
Filtering on missing data
*
airbnb_listingsd
number_of_rooms ;
SELECT
FROM
WHERE IS NULL
12. Return the listings where number_of_rooms is missing
*
airbnb_listingsd
number_of_rooms ;
SELECT
FROM
WHERE IS NOT NULL
13. Return the listings where number_of_rooms is not missing
>Aggregating Data
Simple aggregations
(number_of_rooms)
airbnb_listings;
SELECT
FROM
SUM
1. Get the total number of rooms available across all listings
(number_of_rooms)
airbnb_listings;
SELECTAVG
FROM
2. Get the average number of rooms per listing across all listings
(number_of_rooms)
airbnb_listings;
SELECT
FROM
MAX
3. Get the listing with the highest number of rooms across all listings
(number_of_rooms)
airbnb_listings;
SELECT
FROM
MIN
4. Get the listing with the lowest number of rooms across all listings
Grouping, filtering, and sorting
country, (number_of_rooms)
airbnb_listings
country;
SELECT
FROM
GROUP BY
SUM
5. Get the total number of rooms for each country
country, (number_of_rooms)
airbnb_listings
country;
SELECT
FROM
GROUP BY
AVG
6. Get the average number of rooms for each country
country, (number_of_rooms)
airbnb_listings
country;
SELECT
FROM
GROUP BY
MAX
7. Get the listing with the maximum number of rooms per country
country, (number_of_rooms)
airbnb_listings
country;
SELECT
FROM
GROUP BY
MIN
8. Get the listing with the lowest amount of rooms per country
country, (number_of_rooms) avg_rooms
airbnb_listings
country
avg_rooms ;
SELECT AS
FROM
GROUP BY
ORDER BY A SC
AVG
9. For each country, get the average number of rooms per listing, sorted by ascending order
country, (number_of_rooms)
airbnb_listings
country ( , );
country;
SELECT
FROM
WHERE IN
GROUP BY
MAX
‘USA’ ‘Japan’
10. For Japan and the USA, get the average number of rooms per listing in each country
country, (city) number_of_cities
airbnb_listings
country;
SELECT AS
FROM
GROUP BY
COUNT
11. Get the number of cities per country, where there are listings
year_listed
airbnb_listings
year_listed
(id) > ;
SELECT
FROM
GROUP BY
HAVINGCOUNT 100
12. Get all the years where there were more than 100 listings per year
Learn Data Skills Online at www.DataCamp.com

>Why use Power BI?
>Power BI Components
Learn Data Skills Online at www.DataCamp.com
>Getting started with Power BI
>Visualizing your first dataset
>Data Visualizations in Power BI
Upload datasets into Power BI
Create relationships in Power BI
Create your first visualization
Aggregating data
Open the Power Query Editor
Using the Power Query Editor? Underneath the Home tab, click on Get Dat?
? Choose any of your datasets and double clic?
? Click on Load if not prior data needs processin?
? If you need to transform the data, click Transform which will launch Power Query. Keep reading this cheat sheet for
how to apply transformations in Power Query?
? Inspect your data by clicking on the Data View
Power BI provides a wide range of data visualizations. Here is a list of the most useful visualizations you have in Power BI
Table: Grid used to display data in a logical series of rows and columns (e.g. all products with sold items)
Cards: Used for displaying a single fact or single data point (e.g. total sales)
Maps: Used to map categorical and quantitative information to spatial locations (e.g. sales per state)
Donut Chart: Similar to pie charts; used to show the proportion of sectors to a whole (e.g. market share)
Pie Chart: Circle divided into slices representing a category's proportion of the whole (e.g. market share)
Treemaps: Used to visualize categories with colored rectangles, sized with respect to their value (e.g. product
category based on sales)
Combo Chart: Combines a column chart and a line chart (e.g. actual sales performance vs target)
Scatter: Displays one set of numerical data along the horizontal axis and another set along the vertical axis (e.g.
relation age and loan)
Area Chart: Based on the line chart with the difference that the area between the axis and line is filled in (e.g.
sales by month)
Line Charts: Used for looking at a numeric value over time (e.g. revenue over time)
Column Charts: Vertical columns for comparing specific values across categories
Bar Charts: Horizontal bars used for comparing specific values across categories (e.g. sales by region)
Sales Performance
SalesPersonID
Employee Database
EmployeeID
? If you have different datasets you want to connect. First, upload them into
Power B?
? Click on the Model View from the left-hand pan?
? Connect key columns from different datasets by dragging one to another
(e.g., EmployeeID to e.g., SalespersonID)
? Click on the Report View and go to the Visualizations pane on the right-hand sid?
?Select the type of visualization you would like to plot your data on. Keep reading this cheat to learn different
visualizations available in Power BI?
? Under the Field pane on the right-hand side, drag the variables of your choice into Values or Axis.
Values let you visualize aggregate measures (e.g. Total Revenue)
Axis let you visualize categories (e.g. Sales Person)
Power BI sums numerical fields when visualizing them under Values. However, you can choose different aggregation?
?Select the visualization you just createa
?Go to the Visualizations section on the right-hand sid?
?Go to Values—the visualized column should be there
? On the selected column—click on the dropdown arrow and change the aggregation (i.e., AVERAGE, MAX,
COUNT, etc..)
While loading dat2
? Underneath the Home tab, click on Get Dat?
? Choose any of your datasets and double clic?
? Click on Transform Datatt
When data is already loade4
?Go to the Data VieB
? Under Queries in the Home tab of the ribbon, click on Transform Data drop-down, then on the Transform Data
button
Appending datasets
You can append one dataset to anothe?
? Click on Append Queries under the Home tab under the Combine grouv
?Select to append either Two tables or Three or more tables
? Add tables to append under the provided section in the same window
Merge Queries
You can use merge tables based on a related column}
? Click on Merge Queries under the Home tab under the Combine grouz
?Select the first table and the second table you would like to merge}
?Select the columns you would like to join the tables on by clicking on the column from the first dataset, and from
the second datase\
?Select the Join Kind that suits your operation:
Left outer Right outer Full outer Inner Left anti Right anti
? Click on Ok—new columns will be added to your current tablett
Data profiling
Data Profiling is a feature in Power Query that provides intuitive information about your dat&
? Click on the View tab in the Query ribbow
? In the Data Preview tab—tick the options you want to visualiz?
?Tick Column Quality to see the amount of missing datF
?Tick Column Distribution to see the statistical distribution under every columw
?Tick Column Profileto see summary statistics and more detailed frequency information of columns
Removing rows
You can remove rows dependent on their location, and propertie?
? Click on the Home tab in the Query ribbow
? Click on Remove Rows in the Reduce Rows group}
? Choose which option to remove, whether Remove Top Rows, Remove Bottom Rows, etc.?
? Choose the number of rows to remov?
?You can undo your action by removing it from the Applied Steps list on the right-hand side
Adding a new column
You can create new columns based on existing or new dat&
? Click on the Add Column tab in the Query ribbow
? Click on Custom Column in the General grouv
?Name your new column by using the New Column Name optiow
?Define the new column formula under the custom column formula using the available data
Replace values
You can replace one value with another value wherever that value is found in a colum|
? In the Power Query Editor, select the cell or column you want to replac?
? Click on the column or value, and click on Replace Values under the Home tab under the Transform grouv
?Fill the Value to Find and Replace With fields to complete your operation
There are three main views in Power BI
report view
This view is the default
view, where you can
visualize data and create
reports
data view
This view lets you examine
datasets associated with
your reports
model view
This view helps you
establish different
relationships between
datasets
There are three components to Power BI—each of them serving different purposes
Power BI Desktop
Free desktop application that
provides data analysis and
creation tools.
Power BI service
Cloud-based version of Power BI
with report editing and publishing
features.
Power BI mobile
A mobile app of Power BI, which
allows you to author, view, and
share reports on the go.
>Power Query Editor in Power BI
Power Query is Microsoft’s data transformation and data preparation engine. It is part of Power BI Desktop, and lets
you connect to one or many data sources, shape and transform data to meet your needs, and load it into Power BI.
What is Power BI?
Power BI is a business intelligence tool that allows you
to effectively report insights through easy-to-use
customizable visualizations and dashboards.
Easy to use—no coding
involved
Integrates seamlessly with
any data source
Fast and can handle large
datasets
>DAX Expressions
Data Analysis Expressions (DAX) is a calculation language used in Power BI that lets you create calculations and
perform data analysis. It is used to create calculated columns, measures, and custom tables. DAX functions are
predefined formulas that perform calculations on specific values called arguments.
Sample data
Throughout this section, we’ll use the columns listed in this sample table of `sales_data`
deal_size
1,000
3,000
2,300
sales_person
Maria Shuttleworth
Nuno Rocha
Terence Mickey
date
30-03-2022
29-03-2022
13-04-2022
customer_name
Acme Inc.
Spotflix
DataChamp
Simple aggregation,
?SUM(<column>) adds all the numbers in a columw
?AVERAGE(<column>) returns the average (arithmetic mean) of all numbers in a columw
?MEDIAN(<column>) returns the median of numbers in a columw
?MIN/MAX(<column>) returns the smallest/biggest value in a columw
?COUNT(<column>) counts the number of cells in a column that contain non-blank value>
?DISTINCTCOUNT(<column>) counts the number of distinct values in a column.
EXAMPLEH
?Sum of all deals — SUM(‘sales_data’[deal_size]_
? Average deal size — AVERAGE(‘sales_data’[deal_size]_
?Distinct number of customers — DISTINCTCOUNT(‘sales_data’[customer_name])
Logical function,
?IF(<logical_test>, <value_if_true>[, <value_if_false>]) check the result of an expression and
create conditional results
EXAMPLEH
? Create a column called large_deal that returns “Yes” if deal_size is bigger than 2,000 and “No” otherwise
large_deal = IF( ‘sales_data’[deal_size] > 2000, “Yes”, “No”)
Text Function,
?LEFT(<text>, <num_chars>) returns the specified number of characters from the start of a tex\
?LOWER(<text>) converts a text string to all lowercase letter>
?UPPER (<text>) converts a text string to all uppercase letter>
?REPLACE(<old_text>, <start_num>, <num_chars>, <new_text>) replaces part of a text string with a
different text string.
EXAMPLEH
? Change column customer_name be only lower case 

customer_name = LOWER(‘sales_data’[customer_name])
Date and time function,
?CALENDAR(<start date>, <end date>) generates a column of continuous sets of date>
?DATE(<year>, <month>, <day>) returns the specified date in the datetime forma\
?WEEKDAY(<date>, <return_type>) returns 1-7 corresponding to the day of the week of a date (return_type
indicates week start and end (1: Sunday-Saturday, 2: Monday-Sunday)
EXAMPLEH
?Return the day of week of each deal

week_day = WEEKDAY(‘sales_data’[date], 2)
Power BI Cheat Sheet
Power BI for Business Intelligence
Learn Power BI online at www.DataCamp.com

>Why use Tableau?
>Tableau Versions
Learn Data Skills Online at www.DataCamp.com
>Getting started with Tableau
>Visualizing Your First Dataset
>Creating dashboards with Tableau
The Canvas
Upload a dataset to Tableau
?? Launch Tablea?
?? In the Connect section, under To a File, press on the file format of your choice?
}? For selecting an Excel file, select .xlsx or .xlsx
Creating your first visualization
??Once your file is uploaded, open a Worksheet and click on the Data pane on the left-hand sid;
??Drag and drop at least one field into the Columns section, and one field into the Rows section at the top
of the canvaw
}? To add more detail, drag and drop a dimension into the Marks card (e.g. drag a dimension over the color square
in the marks card to color visualization components by that dimensionl
%? To a summary insight like a trendline, click on the Analytics pane and drag the trend line into your visualization?
r?You can change the type of visualization for your data by clicking on the Show Me button on the top right
Dashboards are an excellent way to consolidate visualizations and present data to a variety of stakeholders. Here is a
step by step process you can follow to create a dashboard.
When working with Tableau, you will work with Workbooks. Workbooks contain sheets, dashboards, and stories.
Similar to Microsoft Excel, a Workbook can contain multiple sheets. A sheet can be any of the following and can be
accessed on the bottom left of a workbook
Worksheet
A worksheet is a single
view in a workbook. You
can add shelves, cards,
legends, visualizations,
and more in a worksheet
Dashboard
A collection of multiple
worksheets used to
display multiple views
simultaneously
story
A story is a collection of
multiple dashboards and/
or sheets that describe a
data story
There are two main versions of Tableau
Tableau Public
A free version of Tableau that lets you connect to limited
data sources, create visualizations and dashboards, and
publish dashboards online
Tableau Desktop
A paid version of tableau which lets you connect to
all types of data sources, allows you to save work
locally, and unlimited data sizes
>Data Visualizations in Tableau
Tableau provides a wide range of data visualizations to use. Here is a list of the most useful visualizations you
have in Tableau
?? Launch Tablea?
?? In the Connect section under To A File, press on your desired file typ;
}?Select your fil;
%? Click the New Sheet at the bottom to create a new shee?
r? Create a visualization in the sheet by following the steps in the previous sections of this cheat shee?
_?Repeat steps 4 and 5 untill you have created all the visualizations you want to include in your dashboarf
z? Click the New Dashboard at the bottom of the scree?
??On the left-hand side, you will see all your created sheets. Drag sheets into the dashboarf
Y?Adjust the layout of your sheets by dragging and dropping your visualizations
>Creating stories with Tableau
A story is a collection of multiple dashboards and/or sheets that describe a data story
?? Click the New Story at the bottom of the scree?
?? Change the size of the story to the desired size in the bottom left-hand corner of the screen under Sieu
}? Edit the title of the story by renaming the story. To do this, right-click on the story sheet at the bottom
and press Renamu
%?A story is made of story points, which lets you cycle through different visualizations and dashboardw
r? To begin adding to the story, add a story point from the left-hand side. You can add a blank story poin?
_? To add a summary text to the story, click Add a caption and summarize the story poin?
z?Add as many story points as you would like to finalize your data story
Bar Charts: Horizontal bars used for comparing specific values across categories (e.g. sales by region)
Stacked Bar Chart: Used to show categorical data within a bar chart (e.g., sales by region and department)
Side-by-Side Bar Chart: Used to compare values across categories in a bar chart format (e.g., sales by
region comparing product types)
Line Charts: Used for looking at a numeric value over time (e.g., revenue over time)
Scatter Plot: Used to identify patterns between two continuous variables (e.g., profit vs. sales volume)
The canvas is where you’ll create data visualizations
Histogram: Used to show a distribution of data (e.g., Distribution of monthly revenue)
Box-and-Whisker Plot: Used to compare distributions between categorical variables (e.g., distribution of
revenue by region)
Heat Map: Used to visualize data in rows and columns as colors (e.g., revenue by marketing channel)
Highlight Table: Used to show data values with conditional color formatting (e.g., site-traffic by marketing
channel and year)
Symbol Map: Used to show geographical data (e.g., Market size opportunity by state)
Map: Used to show geographical data with color formatting (e.g., Covid cases by state)
Treemap: Used to show hierarchical data (e.g., Show how much revenue subdivisions generate relative to
the whole department within an organization)
Dual Combination: Used to show two visualizations within the same visualization (e.g., profit for a store each
month as a bar chart with inventory over time as a line chart)
What is Tableau?
Tableau is a business intelligence tool that allows you to
effectively report insights through easy-to-use
customizable visualizations and dashboards
Easy to use—no coding
involved
Integrates seamlessly with
any data source
Fast and can handle large
datasets
Tableau Basics Cheat Sheet
Tableau for Business Intelligence
Learn Tableau online at www.DataCamp.com
In the sidebar, you’ll find useful panes for working with dat?
??Data: The data pane on the left-hand side contains all of the fields in the currently selected data sourc;
??Analytics: The analytics pane on the left-hand side lets you add useful insights like trend lines, error bars,
and other useful summaries to visualizations
When opening a worksheet, you will work with a variety of tools and interfaces
Tableau provides a deep ability to filter, format, aggregate, customize, and highlight specific parts of your data
visualizations
The Sidebar
Tableau Data Definitions
>
>
The Anatomy of a Worksheet
Customizing Visualizations with Tableau
When working with data in Tableau, there are multiple definitions to be mindful o?
??Fields: Fields are all of the different columns or values in a data source or that are calculated in the
workbook. They show up in the data pane and can either be dimension or measure fieldw
??Dimensions: A dimension is a type of field that contains qualitative values (e.g. locations, names, and
departments). Dimensions dictate the amount of granularity in visualizations and help reveal nuanced details
in the data
1. Tableau Canvas: The canvas takes up most of the screen on Tableau and is where you can add visualizations
2. Rows and columns: Rows and columns dictate how the data is displayed in the canvas. When dimensions
are placed, they create headers for the rows or columns while measures add quantitative values ?
3. Marks card: The marks card allows users to add visual details such as color, size, labels, etc. to rows and columns.
This is done by dragging fields from the data pane into the marks card ?
??Once you’ve created a visual, click and drag your mouse over the specific portion you want to highlight
Filtering data with highlights
??Right-click on a measure field in the Data pan;
??Go down to Default properties, Aggregation, and select the aggregation you would like to use
?? In the Format menu on the top ribbon, press on Select Workbook. This will replace the Data pane and
allow you to make formatting decisions for the Workboo`
?? From here, select the font, font size, and color
?? Create a visualization by dragging fields into the Rows and Columns section at the top of the scree?
??Drag dimensions into the Marks field, specifically into the Color squar;
}? To change from the default colors, go to the upper-right corner of the color legend and select Edit Colors. This
will bring up a dialog that allows you to select a different palette
Aggregating data
Changing colors
When data is dragged into the Rows and Columns on a sheet, it is aggregated based on the dimensions in the sheet.
This is typically a summed value. The default aggregation can be changed using the steps below:
Color is a critical component of visualizations. It draws attention to details. Attention is the most important
component of strong storytelling. Colors in a graph can be set using the marks card.
Changing fonts
Fonts can help with the aesthetic of the visualization or help with consistent branding. To change the workbook’s font,
use the following steps
Stories examples in Tableau
Dashboard examples in Tableau
2. Once you let go, you will have the option to Keep Only or Exclude the data
3. Open the Data pane on the side bar. Then, you can drag-and-drop a field into the fitlers card just to the
left of the pane.
??Open the Data pane on the left-hand-sid;
??Drag-and-drop a field you want to filter on and add it to the Filters carf
}? Fill out in the modal how you would like your visuals to be filtered on the data
Filtering data with filters
3. Measures: A measure is a type of field that contains quantitative values (e.g. revenue, costs, and
market sizes). When dragged into a view, this data is aggregated, which is determined by the
dimensions in the view
4. Data types: Every field has a data type which is determined by the type of information it contains.
The available data types in Tableau include text, date values, date & time values, numerical values,
boolean values, geographical values, and cluster groups

Data Storytelling & Communication
Learn more online at www.DataCamp.com
Cheat Sheet
>Crafting effective visuals
Choose the best visualization for your story
Each plot type is suited for communicating specific things about specific types of data. Start by choosing an
appropriate plot type.
Line plot
Show changes in numeric
values over time.
Bar plot
Visualizes numeric values
by categories. It can be
ranked or unranked
Scatter plot
Show the relationship
between two numeric
values.
Histogram
Show the distribution of
numeric values.
To learn about all the types of visualizations you can use, check out our Data Visualization Cheat Sheet.
Keep visualizations minimal and avoid clutter
Ruthlessly edit your plots to remove or minimize elements that distract from the message of the plot. In particular,
make non-data elements (parts of the plot that don't directly represent a data value, like the grid lines) less distracting.
A great example comes from Darkhorse Analytics, which showcases exactly the value of decluttering visualizations.
Calories per 100g
French
Fries
Potato
Chips
Bacon Pizza Chili Dog
607
542
533
296
260
Decluttering a visualization in action

(Source: Darkhorse Analytics)
Data visualization decluttering best practices
Use just enough white space to keep the visualization from looking busy
Remove chart borders when applicable
Remove or minimize gridlines or axes when applicable
Clean up axis labels when applicable
Label data directly (as opposed to using a legend)
Remove data markers when applicable
Use special effects (bold, underline, italics, shadows) sparingly
>What is data storytelling?
Data storytelling is often called the last mile of analytics. Sound communication skills, allows data professionals to
drive action out of their insights. According to Brent Dykes, Author of Effective Data Storytelling: How to Drive Change
with Data, Narrative, and Visuals—Data Storytelling is a combination of data, visuals, and narrative.
Data Visuals Narrative
The three elements of data storytelling 

(Source: Effective Data Storytelling: How to Drive Change with Data, Narrative, and Visuals by Brent Dykes)
Use text appropriately
While too much text can add clutter, text can also be an extremely effective tool at highlighting insights within your
visualizations. Cole Nussbaumer Knaflic, Author of Storytelling with Data, provides an excellent example with the
following visualization.
JanFebMarAprMayJunJulAugSepOctNovDec
300
250
200
150
100
50
0
Received
Processed
JanFebMarAprMayJunJulAugSepOctNovDec
300
250
200
150
100
50
0
Received
Processed
202
156
160
126
139
104
149
124
177
140
Please approve the hire of 2 FTEs
Ticket volume over time
2 employees quit in May. We nearly kept up with incoming
volume in the following two months, but fell behind with the
increase in Aug and haven’t been able to catch up since.
Data source: XYZ Dashboard, as of 12/31/2014 | A detailed analysis on tickets processed per person
and time to resolve issues was undertaken to inform this request and can be provided if needed.
2014
to backfill those who quit in the past year
Number of tickets
How text can be a useful visual tool when crafting effective visuals

(Source: Storytelling with Data by Cole Nussbaumer Knaflic)
Using text in data visualizations
When applicable, label axes and titles for clarity
Label important data points when necessary
Provide useful context around insights within the title or subtitle
Adjust font size when highlighting specific messages within your labels
When applicable, try to answer common audience questions with labels
Use colors effectively
The fundamentals of color theory in data visualization
Color is one of the most powerful tools available for emphasizing different aspects of your data visualization. Here are
different properties to keep in mind when choosing an appropriate color palette for your visualization.
Hue represents the range of possible colors, from red, through orange, green and blue, to purple and back to red.
Chroma is the intensity of the color, from grey to a bright color.
Luminance is the brightness of the color, from black to white.
There are three common types of color palettes, that depend on these dimensions.
Type
Qualitative
Sequential
Diverging
Purpose
Distinguish unordered
categories
Showcase intensity of a
single variable
Compare between two
groups
What to vary
Hue
Chroma or luminance
Chroma or luminance with two hues
Example
A bar chart of 2022 smartphone sales for
different smartphone manufacturers
A map showcasing Covid-19 vaccination
prevalence
Voter registration prevalence by political party
in the USA
Do not mislead with data stories
The fastest way to lose credibility when presenting data stories is to inadvertently (or intentionally) mislead with your
data insights. Here are top best practices to avoid misleading with data stories.
Same Data, Different Y-Axis
20082009201020112012
3.154%
3.152%
3.150%
3.148%
3.146%
3.144%
3.142%
3.140%
Interest rates
20082009201020112012
3.50%
3.00%
2.50%
2.00%
1.50%
1.00%
0.50%
0.00%
Interest rates
Starting the y-axis at the smallest value or at zero dramatically changes the story told by the plot
Best practices to avoid misleading with data stories
If you are visualizing times series data, make sure your time horizons are large enough to truly represent the data
If the relative size of each value is important, then ensure that your axes start with zero
Ensure that axes scales are appropriate given the data you’re treating
If you are sampling data for descriptive purposes, make sure the sample is representative of the broader population
Use centrality measures such as mean or median to provide context around your data
Choose the best medium to share your story
There are different ways you can deliver a data story. The importance of each is different depending on the audience
of your data story and the setting you’re delivering your data story in.
Type
Presentation
Long-form report
Notebook
Dashboard
Important considerations
Ensure the length of your presentation is appropriate
Leave any highly technical details to the appendix
Ensure there is a narrative arc to your presentation
Be extra diligent about providing useful context around data visualizations
and insights
Leave any highly technical details to the appendix
Ensure that you provide useful context on how you arrived at a certain
conclusion
Make use of the dashboard grid layout
Organize data insights from left to right, top to bottom
Provide useful summary text of key visualizations in your dashboard
Learn more about data storytelling at
www.DataCamp.com
>Crafting effective narratives with data
To communicate effectively, you need to know who your audience is, and what their priorities are. There is a range of
possible audiences you may encounter when presenting, and crafting an audience specific message will be important.
Examples of audiences you may present to are:
$
Executive
Basic data literacy skills
Prioritizes outcomes &
decisions
Cares much more about
business impact than a 1%
incremental gain in a
machine learning model
accuracy or a new
technique you’re using
Data Leader
Data expert
Prioritizes rigour &
insights
Cares much more about
how your arrived at your
insights and to battle test
them for rigour
Business Partner
Advanced data literacy skills
Prioritizes tactical 

next steps
Cares much more about
how your analysis impacts
their workflow, and what
should be their main
takeaway from the data
story
Considerations when crafting audience specific messaging
Aspect What do you need to consider?
Prior knowledge
Priorities
Constraints
What context do they have about the problem?
What is their level of data literacy?
What does the audience care about?
How does your message relate to their goals?
Who is driving decision-making within your audience?
What is the audience’s preferred format?
How much time does an audience have to consume a data story?
Know the audience

>Visualize relationships
Bar chart
One of the easiest charts to
read which helps in quick
comparison of categorical
data. One axis contains
categories and the other axis
represents values
U s e c a s e s
QE Volume of google
searches by regioA
;E Market share in revenue
by product
Column chart
Also known as a vertical bar
chart, where the categories
are placed on the x-axis.
These are preferred over bar
charts for short labels, date
ranges, or negatives in values
U s e c a s e s
QE Brand market shar?
;E Profit Analysis by region
Scatter plot
Most commonly used chart
when observing the
relationship between two
variables. It is especially
useful for quickly surfacing
potential correlations
between data points
U s e c a s e s
QE Display the relationship
between time-on-platform
and churA
;E Display the relationship
between salary and years
spent at company
Connected scatterplot
A hybrid between a scatter
plot and a line plot, the
scatter dots are connected
with a line
U s e c a s e s
QECryptocurrency price
inde
;E Visualizing timelines and
events when analyzing
two variables
Bubble chart
Often used to visualize data
points with 3 dimensions,
namely visualized on the x-
axis, y-axis, and with the size
of the bubble. It tries to show
relations between data points
using location and size
U s e c a s e s
QE Adwords analysis: CPC vs
Conversions vs Share of
total conversion[
;ERelationship between life
expectancy, GDP per
capita, & population size
Word cloud chart
Data
Science
Engineer
Analyst
A convenient visualization for
visualizing the most prevalent
words that appear in a text
U s e c a s e s
QE Top 100 used words by
customers in customer
service tickets
How to use this cheat sheet
Use this cheat sheet for inspiration when making your next data visualizations. For more data visualization cheat sheets,
check out our cheat sheets repository . here
The Data Visualization Cheat Sheet
Learn Data Visualization online at www.DataCamp.com
>Part-to-whole charts
Pie chart
One of the most common ways to
show part to whole data. It is also
commonly used with percentages
U s e c a s e s
QE Voting preference by age grou9
;E Market share of cloud providers
Donut pie chart
The donut pie chart is a variant of the
pie chart, the difference being it has a
hole in the center for readability
U s e c a s e s
QE Android OS market shar?
;E Monthly sales by channel
Heat maps
Heatmaps are two-dimensional charts
that use color shading to represent
data trends.
U s e c a s e s
QE Average monthly temperatures
across the year?
;E Departments with the highest
amount of attrition over time
Stacked column chart
Best to compare subcategories within
categorical data. Can also be used to
compare percentages
U s e c a s e s
QEQuarterly sales per regioA
;E Total car sales by producer
Treemap charts
2D rectangles whose size is
proportional to the value being
measured and can be used to display
hierarchically structured data
U s e c a s e s
QEGrocery sales count with
categorie[
;EStock price comparison by
industry and company
>Capture distributions
Histogram
Shows the distribution of a
variable. It converts
numerical data into bins as
columns. The x-axis shows
the range, and the y-axis
represents the frequency
U s e c a s e s
QE Distribution of salaries in
an organizatioA
;E Distribution of height in
one cohort
Box plot
Shows the distribution of a
variable using 5 key
summary statistics—
minimum, first quartile,
median, third quartile, and
maximum
U s e c a s e s
QEGas efficiency of vehicle[
;E Time spent reading across
readers
Violin plot
A variation of the box plot.e
It also shows the full
distribution of the data
alongside summary statistics
U s e c a s e s
QE Time spent in restaurants
across age group[
;ELength of pill effects by
dose
Density plot
Visualizes a distribution by
using smoothing to allow
smoother distributions and
better capture the
distribution shape of the data
U s e c a s e s
QE Distribution of price of
hotel listing[
;EComparing NPS scores by
customer segment
>Visualize a flow
Sankey chart
Useful for representing flows in
systems. This flow can be any
measurable quantity
U s e c a s e s
QEEnergy flow between
countrie[
;ESupply chain volumes
between warehouses
Chord chart
Useful for presenting
weighted relationships or
flows between nodes.
Especially useful for
highlighting the dominant or
important flows
U s e c a s e s
QEExport between countries
to showcase biggest
export partner[
;ESupply chain volumes
between the largest
warehouses
Network chart
Similar to a graph, it
consists of nodes and
interconnected edges. It
illustrates how different
items have relationships
with each other
U s e c a s e s
QEHow different airports are
connected worldwide?
;ESocial media friend group
analysis
>Visualize a single value
Card
$7.47M
Total Sales
Cards are great for showing
and tracking KPIs in
dashboards or presentations
U s e c a s e s
QERevenue to date on a
sales dashboarW
;E Total sign-ups after a
promotion
Table chart
Best to be used on small
datasets, it displays tabular
data in a table
U s e c a s e s
QE Account executive
leaderboard[
;ERegistrations per webinar
Gauge chart
This chart is often used in
executive dashboard reports
to show relevant KPIs
U s e c a s e s
QENPS score[
;ERevenue to target
>Capture a trend
Line chart
The most straightforward way to
capture how a numeric variable is
changing over time
U s e c a s e s
QERevenue in $ over tim?
;EEnergy consumption in kWh
over tim?
rEGoogle searches over time
Multi-line chart
Captures multiple numeric
variables over time. It can include
multiple axes allowing comparison
of different units and scale ranges
U s e c a s e s
QE Apple vs Amazon stocks
over tim?
;ELebron vs Steph Curry
searches over tim?
rE Bitcoin vs Ethereum price
over time
Area chart
Shows how a numeric value
progresses by shading the area
between line and the x-axis
U s e c a s e s
QE Total sales over tim?
;E Active users over time
Stacked area chart
Most commonly used variation of
area charts, the best use is to track
the breakdown of a numeric value
by subgroups
U s e c a s e s
QE Active users over time by
segmen?
;E Total revenue over time by
country
Spline chart
Smoothened version of a line chart.
It differs in that data points are
connected with smoothed curves
to account for missing values, as
opposed to straight lines
U s e c a s e s
QEElectricity consumption over
tim?
;ECO2 emissions over time
Learn Data Skills Online at
www.DataCamp.com

>Key Definitions
>Categorical Data—Trail Mix
>Numerical Dataset—Glasses of Water
>Correlation
Throughout this cheat sheet, you’ll find terms and specific statistical jargon being used. Here’s a rundown of all the
terms you may encounter.
b| Variable: In statistics, a variable is a quantity that can be measured or counted. In data analysis, a variable is
typically a column in a data frame|
`| Descriptive statistics: Numbers that summarize variables. They are also called summary statistics or aggregations|
P| Categorical data: Data that consists of discrete groups. The categories are called ordered (e.g., educational levels)
if you can sort them from lowest to highest, and unordered otherwise (e.g., country of origin)|
K| Numerical data: Data that consists of numbers (e.g., age).
To illustrate statistical concepts on categorical data, we’ll be using an unordered
categorical variable, consisting different elements of a trail mix. Our categorical
variable contains 15 almonds, 13 cashews, and 25 cranberries.
Counts and Proportions
Counts and proportions are measures of how much data you have. They allow you to understand how many data
points belong to different categories in your data.?
? A count is the number of times a data point occurs in the dataset|
? A proportion is the fraction of times a data point occurs in the dataset.
Food category
Almond
Cashew
Cranberry
Count
15
13
25
Proportion
15 / 48 = 0.283
13 / 48 = 0.245
25 / 48 = 0.472
Visualizing Categorical Variables
Bar plot
One of the easiest charts to read
which helps in quick comparison of
categorical data. One axis contains
categories and the other axis
represents values
Stacked bar chart
Best to compare subcategories within
categorical data. Can also be used to
compare proportions
Treemap chart
2D rectangles whose size is
proportional to the value being
measured and can be used to display
hierarchically structured data
Cheat Sheet
Descriptive Statistics
Learn more online at www.DataCamp.com
Visualizing Numeric Variables
There are a variety of ways of visualizing numerical data, here’s a few of them in action:
Histogram
0 300
Shows the distribution of a variable. It converts numerical
data into bins as columns. The x-axis shows the range, and
the y-axis represents the frequency
Box plot
Q1 Q3
Maximum
Median
Minimum
Shows the distribution of a variable using 5 key summary
statistics—minimum, first quartile, median, third quartile,
and maximum
300ml 60ml 300ml 120ml 180ml 180ml 300ml
To illustrate statistical concepts on numerical data, we’ll be using a numerical
variable, consisting of the volume of water in different glasses.
Measures of Center
Measures of center allow you to describe or summarize your data by capturing one value that describes the center of
its distribution.
Measure
Arithmetic mean
Median
Mode
Definition
The total of the values
divided by how many
values there are
The middle value, when
sorted from smallest to
largest
The most common value
How to find it
7
)
)
180ml
300ml 300ml300ml
Result
205.7 ml
180 ml
300 ml
Other Measures of Location
There are other measures that you can use, that can help better describe or summarize your data.
Measure
Minimum
Maximum
Definition
The lowest value in your
data
The highest value in your
data
How to find it
60ml
300ml
Result
60 ml
300 ml
? Percentile: Cut points that divide the data into 100 intervals with the same amount of data in each interval (e.g., in
the water cup example, the 100th percentile is 300 mls
?Quartile: Similar to the concept of percentile, but with four intervals rather than 100. The first quartile is the same
as the 25th percentile, which is 120 ml. The third quartile is the same as the 75th percentile, which is 300 ml.
Measures of Spread
Sometimes, rather than caring about the size of values, you care about how different they are.
Measure
Range
Variance
Inter-quartile range
Definition
The highest value minus
the lowest value
The sum of the squares of
the differences between
each value and the mean,
all divided by one less
than the number of data
points
The third quartile minus
the first quartile
How to find it
300ml60ml
(7 - 1)
Mean
+ ... +
2
60ml
)-
)
Mean
2
300ml
)-
)
300ml120ml
Result
240 ml
9428.6 ml
2
180 ml
Learn Data Skills Online at
www.DataCamp.com
Strong negative Weak negative No correlation Weak positive Strong positive
Correlation is a measure of the linear relationship between two variables. That is, when one variable goes up, does the
other variable go up or down? There are several algorithms to calculate correlation, but it is always a score between -1
and +1.e
For two variables, X and Y, correlation has the following interpretation:
Correlation score
-1
Between -1 and 0
0
Between 0 and +1
+1
Interpretation
When X increases, Y decreases. Scatter plot forms a perfect straight line with negative slope
When X increases, Y decreases
There is no linear relationship between X and Y, so the scatter plot looks like a noisy mess
When X increases, Y increases
When X increases, Y increases. Scatter plot forms a perfect straight line with positive slope
Note that correlation does not account for non-linear effects, so if X and Y do not have a straight-line relationship,
the correlation score may not be meaningful.

Introduction to
Probability Rules 

Cheat Sheet
Learn statistics online at www.DataCamp.com
>Definitions
The following pieces of jargon occur frequently when discussing probability.
Event: A thing that you can observe whether it happens or not.
Probability: The chance that an event happens, on a scale from 0 (cannot happen) to 1 (always
happens). Denoted P(event).
Probability universe: The probability space where all the events you are considering can either
happen or not happen.
Mutually exclusive events: If one event happens, then the other event cannot happen (e.g., you
cannot roll a dice that is both 5 and 1).
Independent events: If one event happens, it does not affect the probability that the other event
happens (e.g., the weather does not affect the outcome of a dice roll).
Dependent events: If one event happens, it changes the probability that the other event happens.
(e.g., the weather affects traffic outcomes).
Conjunctive probability (a.k.a. joint probability): The probability that all events happen.
Disjunctive probability: The probability that at least one event happens.
Conditional probability: The probability that one event happens, given another event happened.
>
Complement Rule: Probability of events not
happening
A
A’
Complement of A:A’
Definition: The complement of A is the probability that event A does not
happen. It is denoted A' or Acᶜ
Formula: P(A')=1 - P(A)
Example: The probability of basketball player Stephen Curry successfully
shooting a three-pointer is 0.43. The complement, the probability that he
misses, is 1 - 0.43 = 0.57.
>
Multiplication Rules: Probability of two
events happening
Mutually exclusive events
A B
Mutually exclusive (disjoint)
Definition: The probability of two mutually exclusive events happening is zero.
Formula: P(A ∩ B)=0
Example: If the probability of it being sunny at midday is 0.3 and the
probability of it raining at midday is 0.4, the probability of it being sunny and
rainy is 0, since these events are mutually exclusive.
Independent events
Intersection A ∩ B
A
Definition: The probability of two independent events happening is the product
of the probabilities of each event.
Formula: P(A ∩ B)=P(A) P(B)
Example: If the probability of it being sunny at midday is 0.3 and the
probability of your favorite soccer team winning their game today is 0.6, the
then probability of it being sunny at midday and your favorite soccer team
winning their game today is 0.3 * 0.6 = 0.18.
The conjunctive fallacy
Definition: The probability of both events happening is always less than or equal to the probability of one event
happening. That is P(A ∩ B)≤ P(A), and P(A ∩ B)≤ P(B). The conjunctive fallacy is when you don't think
carefully about probabilities and estimate that probability of both events happening is greater than the
probability of one of the events.
Example: A famous example known as 'The Linda problem" comes from a 1980s research experiment. A fictional
person was described:
Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply
concerned with issues of discrimination and social justice and also participated in anti-nuclear demonstrations.
Participants had to choose which statement had a higher probability of being true:
niLinda is a bank teller
biLinda is a bank teller and is active in the feminist movement.
Many participants chose fell for the conjunctive fallacy and chose option 2, even though it must be less likely
than option 1 using the multiplication rule.
>
Bayes Rule: Probability of an event
happening given another event happened
BAB
Definition: For dependent events, the probability of event B happening
given that event A happened is equal to the probability that both events
happen divided by the probability that event A happens. Equivalently, it is
equal to the probability that event A happens given that event B
happened times the probability of event B happening divided by the
probability that event A happens.
Formula: P(B|A)=P(A ∩ B) /P(A)=P(A|B)P(B)/P(A)
Example: Suppose it's a cloudy morning and you want to know the
probability of rain today. If the probability it raining that day given a
cloudy morning is 0.6, and the probability of it raining on any day is 0.1,
and the probability of it being cloudy on any day is 0.3, then the
probability of it raining given a cloudy morning is 0.6 * 0.1 / 0.3 = 0.2.
That is, if you have a cloudy morning it is twice as likely to rain than if
you didn't have a cloudy morning, due to the dependence of the events.
>
Odds: Probability of event happening
versus not happening
Definition: The odds of event A happening is the probability that the event happens divided by the probability
that the event doesn't happen.
Formula: Odds(A)=P(A)/P(A')=P(A)/(1-P(A))
Example: The odds of basketball player Stephen Curry successfully shooting a three-pointer is the probability
that he scores divided by the probability that he misses, 0.43 / 0.57 = 0.75.
The disjunctive fallacy
Definition: The probability of at least one event happening is always greater than or equal to the
probability of one event happening. That is P(A ∪ B) P(A), and P(A ∪ B) P(B). The disjunctive
fallacy is when you don't think carefully about probabilities and estimate that the probability of at least
one event happening is less than the probability of one of the events.
Example: Returning to the "Linda problem", consider having to rank these two statements in order of
probability:
niLinda is a bank teller
biLinda is a bank teller or is active in the feminist movement.
The disjunctive fallacy would be to think that choice 1 had a higher probability of being true, even
though that is impossible because of the additive rule of probabilities.
Learn Statistics Online at
www.DataCamp.com
>
Addition Rules: Probability of at least one
event happening
Mutually exclusive events
A B
Mutually exclusive (disjoint)
Definition: The probability of at least one mutually exclusive event happening is
the sum of the probabilities of each event happening.
Formula: P(A ∪ B)=P(A) + P(B)
Example: If the probability of it being sunny at midday is 0.3 and the
probability of it raining at midday is 0.4, the probability of it being sunny or
rainy is 0.3 + 0.4 = 0.7, since these events are mutually exclusive.
Independent events
B A
Union A U B
Definition: The probability of at least one mutually exclusive event happening
is the sum of the probabilities of each event happening minus the probability
of both events happening.
Formula: P(A ∪ B)=P(A) + P(B) - P(A ∩ B)
Example: If the probability of it being sunny at midday is 0.3 and the
probability of your favorite soccer team winning their game today is 0.6, the
then probability of it being sunny at midday or your favorite soccer team
winning their game today is 0.3 + 0.6 - (0.3 * 0.6) = 0.72.
B

>How to use this cheat sheet
Python is the most popular programming language in data science. It is easy to learn and comes with a wide array of
powerful libraries for data analysis. This cheat sheet provides beginners and intermediate users a guide to starting
using python. Use it to jump-start your journey with python. If you want more detailed Python cheat sheets, check out
the following cheat sheets below:
Importing data in python Data wrangling in pandas
Python Basics
Learn Python online at www.DataCamp.com
Python Cheat Sheet for Beginners
>Accessing help and getting object types
1 1
'a'
+ # Everything after the hash symbol is ignored by Python
# Display the documentation for the max function
# Get the type of an object — this returns str
help(max)
type( )
>Importing packages
Python packages are a collection of useful tools developed by the open-source community. They extend the
capabilities of the python language. To install a new package (for example, pandas), you can go to your command
prompt and type in pip install pandas. Once a package is installed, you can import it as follows.
pandas
pandas pd
pandas DataFrame
import
import as
from import
# Import a package without an alias
# Import a package with an alias
# Import an object from a pac kage
>The working directory
The working directory is the default file path that python reads or saves files into. An example of the working directory
is ”C://file/path". The os library is needed to set and get the working directory.
os
os.getcwd()
os.setcwd( )
import # Import the operating system pac kage
# Get the current director y

# Set the working directory to a ne w file path"new/working/directory"
>Operators
Arithmetic operators
102 37
102 37
4 6
22 7
+
-
*
/
# Add two numbers with +
# Subtract a number with -
# Multiply two numbers with *
# Divide a number by another with /
22 7
3 4
22 7
//
^
%
# Integer divide a number with //
# Raise to the power with ^
# Returns 1 # Get the remainder after
division with %
Assignment operators
a =
x[ ] =
5
0 1
# Assign a value to a
# Change the value of an item in a list
Numeric comparison operators
3 3
3 3
31
==
!=
>
# Test for equality with ==
# Test for inequality with !=
# Test greater than with >
3 3
3 4
3 4
>=
<
<=
# Test greater than or e qual to with >=
# Test less than with <
# Test less than or equal to with <=
Logical operators
~( == )
( != ) & ( < )
2 2
1 1 1 1
# Logical NOT with ~
# Logical AND with &
( >= ) | ( < )
(!= ) ^ ( < )
1 1 1 1
1 1 1 1
# Logical OR with |
# Logical XOR with ^
>Getting started with lists
A list is an ordered and changeable sequence of elements. It can hold integers, characters, floats, strings, and even objects.
Creating lists
# Create lists with [], elements separated by comma s
x = [, , ]13 2
List functions and methods
x. (x)
x.sort()
(x)
x. ()
x.count( )
sorted
reversed
reversed
# Return a sorted copy of the list e .g., [1,2,3]
# Sorts the list in-place (replaces x)
# Reverse the order of elements in x e .g., [2,3,1]
# Reverse the list in-placen
# Count the number of element 2 in the list2
Python lists are zero-indexed (the first element has index 0). For ranges, the first element is included but the last is not.
x = [, , , , ]
x[ ]
x[ ]
# Define the list
n
# Select the 0th element in the lis t
# Select the last element in the lis t
'a' 'b' 'c' 'd' 'e'
0
-1
x[:]
x[:]
x[:]
13
2
3
# Select 1st (inclusive) to 3rd (exclusive)
# Select the 2nd to the end
# Select 0th to 3rd (exclusive)
# Define the x and y list s
x = [, , ]n
y = [, , ]
13 6
1015 21
x + y
* x
# Returns [1, 3, 6, 10, 15, 21]n
# Returns [1, 3, 6, 1, 3, 6, 1, 3, 6] 3
>Getting started with dictionaries
A dictionary stores data values in key-value pairs. That is, unlike lists which are indexed by position, dictionaries are indexed
by their keys, the names of which must be unique.
Creating dictionaries
# Create a dictionary with {}
{ : , : , : }'a' 1 'b' 4'c'9
Dictionary functions and methods
Selecting dictionary elements
x = { : , :, :}
x.keys()
x.values()
'a' 1 'b' 2 'c' 3# Define the x ditionar y
# Get the keys of a dictionary, returns dict_keys(['a', 'b', 'c'])
# Get the values of a dictionary , returns dict_values([1, 2, 3])n
x[ ] 'a'# 1 # Get a value from a dictionary by specifying the key
>NumPy arrays
NumPy is a python package for scientific computing. It provides multidimensional array objects and efficient operations
on them. To import NumPy, you can run this Python code import numpy as nn
Creating arrays
# Convert a python list to a NumPy array

12 3 # Returns array([1,2,3])
# Return a sequence from start (inclusive) to end (exclusive )

# Returns array([1, 2, 3, 4])
# Return a stepped sequence from start (inclusive) to end (exclusive )

# Returns array([1, 3])
# Repeat values n times

# Returns array([1, 1, 1, 3, 3, 3, 6, 6, 6])
# Repeat values n times
# Returns array([1, 3, 6, 1, 3, 6, 1, 3, 6])
np.array([, , ])
np.arange(,)
np.arange(, ,)
np.repeat([, , ], )
np.tile([, , ], )
15
15 2
1 3 6 3
13 6 3
>Math functions and methods
np.quantile(x, q)
np. (x, n)
np.var(x)
np.std(x)
# Calculate q-th quantilen
# Round to n decimal places n
# Calculate variance
# Calculate standard deviation
round
All functions take an array as the input.
np.log(x)
np.exp(x)
np.(x)
np.(x)
np.(x)
np.mean(x)
# Calculate logarithm
# Calculate exponential
# Get maximum value
# Get minimum value
# Calculate sum
# Calculate mean
max
min
sum
>Getting started with characters and strings
# Create a string with double or single quotes

# Embed a quote in string with the escape character \
# Create multi-line strings with triple quotes
str # Get the character at a specific position
str # Get a substring from starting to ending index (exclusive )
"DataCamp"
"He said, \"DataCamp\""
"""
A Frame of Data
Tidy, Mine, Analyze It
Now You Have Meaning
Citation: https://mdsr-book.github.io/haikus.html
"""

0
0 2
[ ]
[:]
Combining and splitting strings
"Data" "Framed"
3 "data "
"beekeepers" " e"
+ n
* n
.split( )
# Concatenate strings with +, this returns 'DataFramed'
# Repeat strings with *, this returns 'data data data '
# Split a string on a delimiter , returns ['b', '', 'k', '', 'p', 'rs']n
# Concatenate DataFrames verticall y
# Concatenate DataFrames hori zontally
# Get rows matching a condition
# Drop columns by nam e
# Rename columns
# Add a new column
pd.concat([df, df])
pd.concat([df,df],axis= )
df.query( )
df.drop(columns=[ ] )
df.rename(columns={ : })
df.assign(temp_f= / * df[ ] + )
"columns"
'logical_condition'
'col_name'
"oldname" "newname"
95 'temp_c' 32
# Calculate the mean of each column
# Get summary statistics by column
# Get unique rows
# Sort by values in a column
# Get rows with largest values in a column
df.mean()
df.agg(aggregation_function)
df.drop_duplicates()
df.sort_values(by= )
df.nlargest(n, )
'col_name'
'col_name'
>Getting started with DataFrames
Pandas is a fast and powerful package for data analysis and manipulation in python. To import the package, you can
use import pandas as pd. A pandas DataFrame is a structure that contains two-dimensional data stored as rows and
columns. A pandas series is a structure that contains one-dimensional data.
Creating DataFrames
# Create a dataframe from a dictionar y
pd.DataFrame({
: [, , ],
: np.array([, , ]),
: [, , ]
})
'a' 1 2 3
'b' 4 4 6
'c' 'x' 'x' 'y'
# Create a dataframe from a list of dictionarie s
pd.DataFrame([
{ : , :, : },n
{ : , :, : },n
{ : , :, : }
])
'a' 1 'b' 4 'c' 'x'
'a' 1 'b' 4 'c' 'x'
'a' 3 'b' 6 'c' 'y'
Selecting DataFrame Elements
Select a row, column or element from a dataframe. Remember: all positions are counted from zero, not one.
df.iloc[]
df[ ]
df[[ , ]]n
df.iloc[:, ]
df.iloc[, ]
# Select the 3rd row
# Select one column by nam e
# Select multiple columns by name s
# Select 2nd column
# Select the element in the 3rd row, 2nd column
3
'col'
'col1' 'col2'
2
3 2
Manipulating DataFrames
Selecting list elements
Concatenating lists
Mutate strings
str
str
str
str
str
=
.upper()
.lower()
.title()
.replace( , )
"Jack and Jill"
"J" "P"
# Define str
# Convert a string to uppercase , returns 'JACK AND JILL'
# Convert a string to lo wercase, returns 'jack and jill'n
# Convert a string to title case , returns 'Jack And Jill'
# Replaces matches of a substring with another, returns 'Pack and Pill'

>How to use this cheat sheet
R is one of the most popular programming languages in data science and is widely used across various industries and
in academia. Given that it’s open-source, easy to learn, and capable of handling complex data and statistical
itp*sA ts*Op /v vct vhoaOiovscovsRomoRRo vaOisAs*pavoph*ROpiopsvmORvitppv tstv a*ops* s vsO tpe+
This cheat sheet will cover an overview of getting started with R. Use it as a handy, high-level reference for a quick
start with R. For more detailed R Cheat Sheets, follow the highlighted cheat sheets below.
xts Cheat Sheet data.table Cheat Sheet
>Using packages
R packages are collections of functions and tools developed by the R community. They increase the power of R by
improving existing base R functionalities, or by adding new ones.
install.packages(“tidyverse”)
library(tidyverse)
#Lets you install new packages (e.g., tidyverse package)
#Lets you load and use packages (e.g., tidyverse package)
>The working directory
The working directory is a file path that R will use as the starting point for relative file paths. That is, it's the default
location for importing and exporting files. An example of a working directory looks like ”C://file/path”
getwd()
setwd(“C://file/path”) -
#Returns your current working directory
#Changes your current working directory to a desired filepath
>Operators
R has multiple operators that allow you to perform a variety of tasks. Arithmetic operators let you perform arithmetic
such as addition and multiplication. Relational operators are used to compare between values. Logical operators are
used for Boolean operators.
Arithmetic Operators
a + b
a - b
a * b
a / b
a ^ b
a%%b
a%/%b
#Sums two variables
#Subtracts two variables
#Multiply two variables
#Divide two variables
#Exponentiation of a varia ble
#Remainder of a variable
#Integer division of varia bles
Relational Operators
a == b
a != b
a > b
a < b
a >= b
a <= b
#Tests for equality
#Tests for inequality
#Tests for greater than
#Tests for lower than
#Tests for greater than or e qual to
#Tests for less than or e qual to
Logical Operators
!
&
&&
|
||
#Logical NOT
#Element-wise logical AND
#Logical AND
#Element-wise logical OR
#Logical OR
Assignment Operators
x <- 1
x = 1
# Assigns a variable to x
#Assigns a variable to x
Other Operators
%in%
$
%>%
#Identifies whether an ele ment belongs to a vectort
#Allows you to access o bjects stored within an o bject
#Part of magrittr package, it’s used to pass objects to functions
>Accessing help
Accessing help files and documentation
?max
?tidyverse
??"max"
#Shows the help documentation for the max function
#Shows the documentation for the tidyverse packag e
#Returns documentation associated with a given input
Information about objects
str(my_df)
class(my_df)
#Returns the structure and infor mation of a given object
#Returns the class of a given o bject
>Getting started with vectors
Vectors are one-dimension arrays that can hold numeric data, character data, or logical data. In other words, a vector
is a simple tool to store data.
Creating vectors
Input
c(1,3,5)
1:7
seq(2,8,by = 2)
rep(2,8,times = 4)
rep(2,8,each = 3)
Output
1 3 5
1 2 3 4 5 6 7
2 4 6 8
2 8 2 8 2 8 2 8
2 2 2 8 8 8
Description
Creates a vector using elements
separated by commas
Creates a vector of integers
between two numbers
Creates a vector between two
numbers, with a specified interval
between each element.
Creates a vector of given
elements repeated a number of
times.
Creates a vector of given
elements repeating each element
a number of times.
Vector functions
These functions perform operations over a whole vector.
sort(my_vector)
rev(my_vector)
table(my_vector)
unique(my_vector)
#Returns my_vector sorted
#Reverses order of my_vector
#Count of the values in a vecto r
#Distinct elements in a vector
Selecting vector elements
These functions allow us to refer to particular parts of a
vector.
my_vector[6]
my_vector[-6]
my_vector[2:6]
my_vector[-(2:6)]
my_vector[c(2,6)]
my_vector[x == 5]
my_vector[x < 5 ]
my_vector[x %in% c(2, 5 ,8 )]
#Returns the sixth element of my_vector
#Returns all but the sixth element
#Returns elements two to six
#Returns all elements except
those between the second and the si xth
#Returns the second and si xth
elements
#Returns elements equal to 5
#Returns elements less than 5
#Returns elements
in the set {2, 5, 8}
R for Data Science
Learn R online at www.DataCamp.com
Getting started with R Cheat Sheet
>Math functions
These functions enable us to perform basic mathematical operations within R
log(x)
exp(x)
max(x)
min(x)
mean(x)
sum(x)
median(x)
#Returns the logarith m of a variable
#Returns exponential of a variable
#Returns maximum value of a vector
#Returns minimum value of a vector
#Returns mean of a vector
#Returns sum of a vector
#Returns median of a vector
quantile(x)
round(x, n)
rank(x)
signif(x, n)
var(x)
cor(x, y)
sd(x)
#Percentage quantiles of a vector
#Round to n decimal places
#Rank of elements in a vector
#Round off n significant figure s
#Variance of a vector
#Correlation between two vectors
#Standard deviation of a vector
>Getting started with strings
The “stringr” package makes it easier to work with strings in R - you should install and load this package to use the
following functions.
Find Matches
#Detects the presence of a pattern match in a string
#Detects the presence of a pattern match at the
beginning of a string
#Finds the index of strings that contain pattern match
#Locates the positions of pattern matches in a string
#Counts the number of pattern matches in a string
str_detect(string, pattern, negate = FALSE)
str_starts(string, pattern, negate = FALSE)
str_which(string, pattern, negate = FALSE)
str_locate(string, pattern)
str_count(string, pattern)
Subset
#Extracts substrings from a character vector
#Returns strings that contain a pattern match
#Returns first pattern match in each string as a vecto r
#Returns first pattern match in each string as a matrix
with a column for each group in the patter n
str_sub(string, start = 1L, end = -1L)
str_subset(string, pattern, negate = FALSE)t
str_extract(string, pattern)t
str_match(string, pattern)
Mutate
#Replaces substrings by identifying the substrings
with str_sub() and assigning them to the suaaneat
#Replaces the first matched pattern in each string .
#Replaces all matched patterns in each strin g
#Converts strings to lowercase t
#Converts strings to uppercase t
#Converts strings to title case t
str_sub() <- valuet
str_replace(string, pattern, replacement) t
str_replace_all(string, pattern, replacement)t
str_to_lower(string)t
str_to_upper(string)t
str_to_title(string)
Join and Split
#Repeats strings n ti mes
#Splits a vector of strings into a matrix of substrings
str_dup(string, n)t
str_split_fixed(string, pattern, n)
Order
#Returns the vector of inde xes that sorts a character
vector
#Sorts a character vecto r
str_order(x)t
str_sort(x)
>Getting started with Data Frames in R
A data frame has the variables of a data set as columns and the observations as rows.
#This creates the data fra me df, seen on
the right
df <- data.frame(x = 1:3, y =
c(“h”, “i”, “j”), z = 12:14)
1
2
3
h
i
j
12
13
14
x y z
#This selects all columns of the third row
df[ ,3] 1
2
3
h
i
j
12
13
14
x y z
#This selects the column z
df$z 1
2
3
h
i
j
x y
13
12
14
z
#This selects all rows of the second
column
df[ ,2]
1
2
3
12
13
14
x z
h
i
j
y
#This selects the third colu mn of the
second row
df[2,3]
1
2
3
h
i
j
12
14
x y z
13
>Manipulating Data Frames in R
dplyr allows us to easily and precisely manipulate data frames. To use the following functions, you should install and
load dplyr using install.packages(“dplyr”)
#Takes a sequence of vector,
matrix or data-frame arguments
and combines them by columns
bind_cols(df1, df2)
#Takes a sequence of vector,
matrix or data frame arguments
and combines them by rows
bind_rows(df1, df2)
#Extracts rows that meet logical
criteria
filter(df, x == 2)
#Removes rows with duplicate
values
distinct(df, z)
#Selects rows by position
slice(df, 10:15)
#Selects rows with the highest
values
slice_max(df, z, prop pt
0.25)
#Extracts column values as a
vector, by name or index
pull(df, y)
#Extracts columns as a table
select(df, x, y)
#Moves columns to a new position
relocate(df, x, .after =
last_col())
#Renames columns
rename(df, “age” = z)
#Orders rows by values of a
column from high to low
arrange(df, desc(x))
#Computes table of summaries
summarise(df, total =
sum(x))
#Computes table of summaries.
summarise(df, total =
sum(x))
#Use group_by() to create a "grouped" copy of a table
grouped by columns (similarly to a pivot table in
spreadsheets). dplyr functions will then manipulate
each "group" separately and combine the results
df y t
group_by(z) y t
summarise(total = sum(x)) Try this Cheat Sheet on
DataCamp Workspace
Get Started