Skip to content
Advertisement

Pandas TypeError: unhashable type: ‘list’ when importing from csv

I’m trying to clean some data from a csv file. Here’s an example of the data I’m importing. What I’m trying to do is split the cell by the first comma. The data before the comma goes to one column, the data after goes to another.

Example Data

I’ve set up a function to handle the data:

JavaScript

The csv file is loaded into a dataframe fgd_og_df and I’m trying to put it in two columns of the soil_gINT_df dataframe using the following:

JavaScript

This gives me the following error:

JavaScript

This is the output immediately before the error:

SHALE. <class ‘str’>

1

2

3

<class ‘str’>

SHALE. <class ‘str’>

So it’s getting through the function and giving an error when it tries to take the two strings back into the soil_gINT_df dataframe, but I’m not sure why. There are other text strings that are similar that work, so I’m at a bit of a loss.

Advertisement

Answer

The mistake was here, see chepner’s comment pointing out that the first is a tuple of lists:

JavaScript

Should be:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement