3

I want to save the dataframe df to the .h5 file MainDataFile.h5 :

df.to_hdf ("c:/Temp/MainDataFile.h5", "MainData", mode = "w", format = "table", data_columns=['_FirstDayOfPeriod','Category','ChannelId'])

and get the following error :

*** Exception: cannot find the correct atom type -> > [dtype->object,items->Index(['Libellé_Article', 'Libellé_segment'], dtype='object')]

If I modifify the column 'Libellé_Article' in this way :

df['Libellé_Article'] = str(df['Libellé_Article'])

there is no error anymore, whereas I still get the error message when doing :

df['Libellé_Article'] = df['Libellé_Article'].astype(str)

The problem is that using str() is blowing up my ram.

Any idea ?

3
  • I'm voting to close this question as off-topic because it is an unformatted blob of nonsense.
    – user1804599
    May 7, 2015 at 8:04
  • 2
    Formatting is fixable (done). The question is still unclear, however. Can you reformulate it to contain an actual question? Thanks! May 7, 2015 at 8:06
  • Sorry my browser sent the question before I finished to write it May 7, 2015 at 8:24

2 Answers 2

3

str(df['Libellé_Article']) will convert the contents of the entire column in to single string. It will end up with a very big string. And thats the reason for blowing up your RAM

For example

>> df = pd.DataFrame([1,2,3], columns=['A'])
>> df['A']
0    1
1    2
2    3 
Name: A, dtype: int64

>> str(df['A'])
 '0    1\n1    2\n2    3\nName: A, dtype: int64'
>> df['A'].astype(str)
0    1
1    2
2    3
Name: A, dtype: object

So you should use .astype(str) only, if you want to convert your entire column to type string

2
  • Thanks Kathirmani, you are perfectly right ! So the question remains why I get an error message when applying .astype(str). I suspect a special character in the column 'Libellé_Article', but unable to find which so far. May 7, 2015 at 11:25
  • For that please post some sample data, so that i can try it out locally in my machine May 7, 2015 at 11:40
1
  • The difference here is that .astype(str) is a method for a Pandas series and str() is a function.
  • This is why : .astype(str) will work on series and not on int while str() will work on both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.