From the course: Python Functions for Data Science
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Handle magnitudes and precision in data
From the course: Python Functions for Data Science
Handle magnitudes and precision in data
Properly handling magnitudes and controlling numeric precision is essential for interpreting your data and keeping your results readable when using Python. In this lesson, I'll introduce you to two built-in Python functions that help you do this: abs() and round(). The abs() function returns the absolute value of a number. In other words, its distance from zero on the number line, regardless of whether it's positive or negative. This is useful in situations when you only care about magnitudes-- for example, the size of an error or the distance between two values. Let's say you're analyzing monthly financial data of a business, and you're working with profit values. Your goal is to get the magnitude of the gain or loss for each month. Here I've defined the variables: sept_profit and oct_profit. They represent the profit value for September and October respectively. And I've called the abs() function on each variable to get the absolute value of the profit for September and then for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.