0

I've extracted some data from a data frame and want to save it as a text file

# df is my dataframe with col1, col2...., as column headers
X = df.col1[df['col3']<35].unique()
X[0:3]
>>array(['1998-01-07T11:00:00.000000000', '1998-01-06T23:00:00.000000000',
   '1998-01-28T11:00:00.000000000'], dtype='datetime64[ns]')
np.savetxt('filename', X, delimiter=' ', header='Some Header')

I'm expected it to save the dates but instead, the file contains the first few lines as:

# Some Header 
8.841708000000000000e+17
8.841276000000000000e+17
8.859852000000000000e+1

What am I missing here?

1 Answer 1

1

savetxt's default format for each field is '%.18e', which is a floating point format. Add the fmt argument to change the format, e.g.

np.savetxt('filename', X, fmt='%s', delimiter=' ', header='Some Header')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.