36797

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

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 always get the error message:

'Series' objects are mutable, thus they cannot be hashed

which I found a solution for in connection with groupby but not with filesaving. Somebody has an idea for me?

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))

Answer1:

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-sctipt operator:

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

Also it's probably more readable to pass a list of strings rather than a tuple

Recommend

  • Claims: difference between UPN, Name with Azure AD
  • Downloading cover art URL from Spotify and key-value observing
  • Initialising in Python using Keyword Args without sharing between instances
  • Sort NSArray of NSDictionary objects using NSSortDescriptor
  • Can't map an array of objects for NSManagedObject in RestKit
  • what is the significant of enum in typescript
  • How to receive and store binary data from server in iOS?
  • Mutation of the keys in HashMap causes wrong results
  • Objective C: Terminating app due to uncaught exception 'NSInvalidArgumentException'
  • is their a scatter_update() for placeholder in tensorflow
  • Sending post data nsurlsession
  • Public Mutable Field in Object
  • How to calculate moving median in DataFrame?
  • Why does Rust have both call by value and call by reference?
  • Best way to initialise / clear a string variable cocoa
  • How can I overwrite a file in UWP?
  • 'Series' objects are mutable, thus they cannot be hashed error calling to_csv
  • F# deleting common elements in lists
  • F# NativePtr.stackalloc Unexpected Stack Overflow
  • How can I sum two different columns at once where one contains Decimal objects in pandas?
  • How can I select the most recent and distinct records using LINQ?
  • Convert two columns Pandas data frame to dictionary of list with first column as keys
  • How to concat Pandas dataframe columns
  • C# List of Panels
  • what makes a request a new request in asp.net C#
  • Group list of tuples by item
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Debug.DrawLine not showing in the GameView
  • How to Cache Real-time Data?
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • CSS Linear-gradient formatting issue accross different browsers
  • Fetching methods from BroadcastReceiver to update UI
  • Excel - Autoshape get it's name from cell (value)
  • Check if a string to interpolate provides expected placeholders
  • Display Images one by one with next and previous functionality
  • RestKit - RKRequestDelegate does not exist
  • Traverse Array and Display in markup
  • Python: how to group similar lists together in a list of lists?
  • Python/Django TangoWithDjango Models and Databases