Fix the typerror can’t multiply sequence by float in Python

In today’s short tutorial we’ll help you troubleshoot a type error that you might receive when trying to multiply a sequence (strings, lists or tuples) by a float number in Python. Can’t multiple sequence by float error Let’s run the following code: After entering the product price, as expected, we’ll get the following error: Fixing … Read more

How to subtract dates and times in Python?

In today’s Python automation tutorial we would like to show how you can easily subtract and calculate time differences using the Python language. We’ll use the datetime module to calculate: Difference between two dates Difference between a date and a timedelta object. Subtracting other timedeltas from date objects : years, months, hours, minutes, seconds. Subtract … Read more

Write to a CSV file row by row with Python

This tutorial explains how to use Python 3 to write data line by line into a comma separated value file. We’ll look into several examples: Using the csv module. Using the Pandas Data Analysis library Write text using the CSV module In the first example we’ll use the Python csv library to define a writer … Read more

How to round up Pandas column values?

In today’s tutorial we’ll learn how to round values in Pandas DataFrame columns. We’ll look into several cases: Round float values to the nearest 2 decimals Round float values to nearest 10 / 100 Rounding a Series Persisting changes after rounding up Example DataFrame Let’s get starting by creating a sample DataFrame that you can … Read more

How to total DataFrame columns and rows in Pandas?

In today’s data analysis tutorial we’ll learn how to sum across rows in Pandas DataFrame columns and add a total summary row. Create Example Data We will start by creating some sample data based on a fictitious human resources dataset. Adding a Total Row to the DataFrame We can use the sum() DataFrame method to … Read more