Skip to content
Home » python » Page 8

python

Replacing multiple values in a pandas DataFrame column

Without going into detail, here’s something I truly hate in R: replacing multiple values. In Python’s pandas, it’s really easy. In this blog post I try several methods: list comprehension, apply(), replace() and map(). First, let’s create some dummy data. First, let’s try with list comprehension. The get() function tries… 

Solving “inconsistent use of tabs and spaces in indentation” in Visual Studio Code

Out of the blue, when coding Python in Visual Studio Code, you might run into the following error. “inconsistent use of tabs and spaces in indentation” This happens, because somewhere in your code, indentation is different than in the rest of your code. Generally, Python doesn’t care what kind of… 

Pandas: Solve ‘You are trying to merge on object and int64 columns’

Pandas is the go-to package for anything data science in Python. However, if you’re used to R and the convenience of dplyr or data.table, pandas can be confusing, now and then. For example, the following error is a real newb issue. ValueError: You are trying to merge on object and…