'series' objects are mutable, thus they cannot be hashed error calling to_csv

  • Last Update :
  • Techknowledgy :

Your error comes about because you passed a tuple of Series rather than a tuple of column names/strings:

df.to_csv('alldatcorr.csv', sep = '\t', cols = (df.CO2abs, df.CO2corr))

So you found that this worked:

df.to_csv('corr2.csv', sep = '\t', cols = ('CO2abs', 'CO2corr'))

you could've avoided the ambiguity by just sub-selecting from your df by passing a list and using the sub-script operator:

df[['CO2abs', 'CO2corr']].to_csv('corr2.csv', sep = '\t')

Suggestion : 2

I have a large Dataframe (5 days with one value per second, several columns) of which I'd like to save 2 columns in a csv file with python pandas df.to_csv module., 3 days ago Sep 13, 2015  · I have a large Dataframe (5 days with one value per second, several columns) of which I'd like to save 2 columns in a csv file with python pandas df.to_csv module. I tried different ways but alway... ,which I found a solution for in connection with groupby but not with filesaving. Somebody has an idea for me?, 3 days ago So let’s NOT use the series object as a key. Rather, use only one of its fields.The second option is to convert the series object into some immutable type, … Finally, the last method. You can create a class that will inherit from the …


DateTime 2015 - 07 - 14 00: 00: 00 414.37 2015 - 07 - 14 00: 00: 00 414.37 2015 - 07 - 14 00: 00: 01 414.29 2015 - 07 - 14 00: 00: 02 414.14 2015 - 07 - 14 00: 00: 03 414.21 2015 - 07 - 14 00: 00: 04 414.05 2015 - 07 - 14 00: 00: 05 414.05 2015 - 07 - 14 00: 00: 06 414.2 2015 - 07 - 14 00: 00: 07 414.54 2015 - 07 - 14 00: 00: 08 414.39 Name: CO2abs, dtype: object DateTime

df.to_csv('alldatcorr.csv', sep = '\t', cols = (df.CO2abs, df.CO2corr))
1._
import pandas
import pandas
ser1 = pd.Series(["a", "b", "c", "d", "e"]) print(ser1)
ser1 = pd.Series(["a", "b", "c", "d", "e"]) print(ser1)
0 a 1 b 2 c 3 d 4 e dtype: object
ser2 = pd.Series([192168, "John Smith", "agent", 120000], index=["id", "name", "job_title", "salary"]) print(ser2)
id 192168 name John Smith job_title agent salary 120000 dtype: object
id   192168 name
John Smith job_title
agent salary
120000 dtype: object
dic1 = {
   ser1: "Our series"
}

Suggestion : 3

you now have a Series object with a single value. You can't hash the Series.,The solution is to create Series from the start.,when I set value in dataframe(pandas) there is error: 'Series' objects are mutable, thus they cannot be hashed,Change column value if it does contain one of two substrings - getting a "Series objects are mutable - they cannot be hashed" error?

1._
gene_name = no_headers.iloc[1: , [1]]

This creates a DataFrame because you passed a list of columns (single, but still a list). When you later do this:

gene_name[x]

The solution is to create Series from the start.

gene_type = no_headers.iloc[1: , 0]
gene_name = no_headers.iloc[1: , 1]
disease_name = no_headers.iloc[1: , 2]

Mutable objects are objects which value can be changed. For example, list is a mutable object, since you can append to it. int is an immutable object, because you can't change it. When you do:

a = 5;
a = 3;

Suggestion : 4

'Series' objects are mutable, thus they anycodings_csv cannot be hashed,I have a large Dataframe (5 days with one anycodings_csv value per second, several columns) of which anycodings_csv I'd like to save 2 columns in a csv file anycodings_csv with python pandas df.to_csv module.,Your error comes about because you anycodings_immutability passed a tuple of Series rather than a anycodings_immutability tuple of column names/strings:,I tried different ways but always get the anycodings_csv error message:

Here a part of my Dataframe:

DateTime
2015 - 07 - 14 00: 00: 00 414.37
2015 - 07 - 14 00: 00: 00 414.37
2015 - 07 - 14 00: 00: 01 414.29
2015 - 07 - 14 00: 00: 02 414.14
2015 - 07 - 14 00: 00: 03 414.21
2015 - 07 - 14 00: 00: 04 414.05
2015 - 07 - 14 00: 00: 05 414.05
2015 - 07 - 14 00: 00: 06 414.2
2015 - 07 - 14 00: 00: 07 414.54
2015 - 07 - 14 00: 00: 08 414.39
Name: CO2abs, dtype: object DateTime

Edit: sorry - forgot the code...

df.to_csv('alldatcorr.csv', sep = '\t', cols = (df.CO2abs, df.CO2corr))

Your error comes about because you anycodings_immutability passed a tuple of Series rather than a anycodings_immutability tuple of column names/strings:

df.to_csv('alldatcorr.csv', sep = '\t', cols = (df.CO2abs, df.CO2corr))

So you found that this worked:

df.to_csv('corr2.csv', sep = '\t', cols = ('CO2abs', 'CO2corr'))

you could've avoided the ambiguity by anycodings_immutability just sub-selecting from your df by anycodings_immutability passing a list and using the sub-script anycodings_immutability operator:

df[['CO2abs', 'CO2corr']].to_csv('corr2.csv', sep = '\t')