I'm using Python in Jupyter Notebooks to work with a CSV file. I'm writing the same code in two different versions of Jupyter Notebook--one that's running directly on my computer and another that's running off a kind of emulator within an online lesson from Dataquest. When I open the CSV file and read it into a string on my computer's Jupyter Notebook, the EOL character is \r
but when I do the same on Dataquest's emulator, the EOL character is \n
. I have two questions:
Why does this happen?
How can I write a Python code that tests for the EOL character without opening the file to find out visually?
This code in in a Jupyter notebook on my own Mac.
f = open('US_births_1994-2003_CDC_NCHS.csv', 'r')
data_MyComp = f.read()
data_MyComp
This code is on Dataquest's Jupyter notebook browser emulator.
f = open('US_births_1994-2003_CDC_NCHS.csv', 'r')
data_dataquest = f.read()
data_dataquest
This is a few lines of output from my computer when I run data_MyComp
(note the EOL character is \r
).
'year,month,date_of_month,day_of_week,births\r1994,1,1,6,8096\r1994,1,2,7,7772\r1994,1,3,1,10142\r1994,1,4,2,11248\r1994,1,5,3,11053\r1994,1,6,4,11406\r1994,1,7,5,11251\r1994,1,8,6,8653\r1994,1,9,7,7910\r1994,1,10,1,10498\r1994,1,11,2,11706\r
This is a few lines of output from the Dataquest emulator when I run data_dataquest
(note the EOL character is \n
).
'year,month,date_of_month,day_of_week,births\n1994,1,1,6,8096\n1994,1,2,7,7772\n1994,1,3,1,10142\n1994,1,4,2,11248\n1994,1,5,3,11053\n1994,1,6,4,11406\n