0

I am trying to read in a csv file of stock data which is set out as follows:

        Date           "Open           "High           "Low            "Close          "Volume         "Open Interest  "Ticker

  1999-1-21"       33.07198"       33.60028"       32.96632"       33.07198"          36201"             39"             CS
  1999-1-22"       32.01537"       32.22669"       32.01537"       32.01537"           3667"             38"             CS
  1999-1-25"       32.12103"       32.75499"       32.12103"       32.12103"           2366"             38"             CS
  1999-1-26"       32.01537"       32.01537"       32.01537"       32.01537"          14315"             38"             CS

etc

The delimiter is clearly " but when I run the below code it just reads it in as one column and includes the " in the data.

import pandas as pd

stock1 = 'CS.csv'

x = pd.read_csv(stock1, delimiter='"')

Any help would be appreciated.

1 Answer 1

2

The python parser can parse CSVs with complex regex patterns as the delimiter.

df = pd.read_csv(filename, sep=r'\s*"\s*', engine='python')
print(df)
        Date      Open      High       Low     Close  Volume  Open Interest Ticker
0  1999-1-21  33.07198  33.60028  32.96632  33.07198   36201             39     CS
1  1999-1-22  32.01537  32.22669  32.01537  32.01537    3667             38     CS
2  1999-1-25  32.12103  32.75499  32.12103  32.12103    2366             38     CS
3  1999-1-26  32.01537  32.01537  32.01537  32.01537   14315             38     CS
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.