Skip to content Skip to sidebar Skip to footer

Difference Between Str() And Astype(str)?

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'

Solution 1:

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']
011223Name: A, dtype: int64

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

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

Post a Comment for "Difference Between Str() And Astype(str)?"