1

I'm studying the book "Python for Data Analysis (written by Wes McKinney)."

While working on CH10, I had a problem.

The code below is what I wrote in Google Colab.

!wget https://github.com/wesm/pydata-book/blob/2nd-edition/examples/stock_px_2.csv

close_px = pd.read_csv('stock_px_2.csv', parse_dates=True, index_col=0)

close_px.head()

Then I got this error.

ParserError: Error tokenizing data. C error: Expected 1 fields in line 107, saw 2

How can I fix this?

Thanks!

1
  • 1
    try using the link https://raw.githubusercontent.com/wesm/pydata-book/2nd-edition/examples/stock_px_2.csv Commented Jan 7, 2022 at 7:45

1 Answer 1

1

Using the raw CSV file, I can read the values:

import pandas as pd

csv_url = "https://raw.githubusercontent.com/wesm/pydata-book/2nd-edition/examples/stock_px_2.csv"
close_px = pd.read_csv(csv_url, parse_dates=True, index_col=0)
print(close_px.head())

Output:

            AAPL   MSFT    XOM     SPX
2003-01-02  7.40  21.11  29.22  909.03
2003-01-03  7.45  21.14  29.24  908.59
2003-01-06  7.45  21.52  29.96  929.01
2003-01-07  7.43  21.93  28.95  922.93
2003-01-08  7.28  21.31  28.83  909.93
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.