-1

I have the following code. When i save it. The headers of columns don't save. Could u please guide me?

import numpy as np
import pandas as pd

A = np.random.randint(0, 10, size=36).reshape(6, 6)

df = pd.DataFrame(A,  columns=['one', 'two', 'three','four','five','six'])
np.savetxt("/home/dataset/test.csv",df, delimiter=",")
1
  • savetxt takes a header parameter. Format your column names as a string and use that. Commented Nov 14, 2015 at 17:21

1 Answer 1

2

Use the built-in pandas function for this:

df.to_csv("your_file_path_here")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.