1

I have data in this format:

DAX 20150728 11173.910156
DAX 20150727 11056.400391
DAX 20150724 11347.450195
DAX 20150723 11512.110352

If I try to read the data with print pd.read_csv('DAX.csv'), I get this: [6246 rows x 1 columns]. Obviously pandas can not manage to read the three columns of data and get all the data in one column.

How can I fix this?

1
  • Okay, I see. Thank you very much! Commented Jul 31, 2015 at 11:03

2 Answers 2

1

You need to explicitly pass the separator as the default is comma ',':

In [160]:
t="""DAX 20150728 11173.910156
DAX 20150727 11056.400391
DAX 20150724 11347.450195
DAX 20150723 11512.110352"""
df = pd.read_csv(io.StringIO(t), header=None, sep='\s+',names=['exchange', 'date', 'close'], parse_dates=[1])
df

Out[160]:
  exchange       date         close
0      DAX 2015-07-28  11173.910156
1      DAX 2015-07-27  11056.400391
2      DAX 2015-07-24  11347.450195
3      DAX 2015-07-23  11512.110352

The docs state this.

Sign up to request clarification or add additional context in comments.

Comments

1

did you try:

variable = pd.read_csv('DAX.csv')

and then:

print variable

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.