6

I have exported the gold price data from the brokers. the file has no column names like this

2014.02.13,00:00,1291.00,1302.90,1286.20,1302.30,41906 2014.02.14,00:00,1301.80,1321.20,1299.80,1318.70,46244 2014.02.17,00:00,1318.20,1329.80,1318.10,1328.60,26811 2014.02.18,00:00,1328.60,1332.10,1312.60,1321.40,46226

I read csv to pandas dataframe and it take the first row to be the column names. I am curious how can I set the column names and still have all the data

Thank you

1

1 Answer 1

12

if you don't have a header in the CSV, you can instruct Pandas to ignore it using the header parameter

df = pd.read_csv(file_path, header=None)

to manually assign column names to the DataFrame, you may use

df.columns = ["col1", "col2", ...]

Encourage you to go through the read_csv documentation to learn more about the options it provides.

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.