Search code examples
pythonmachine-learningtext-filesjupyter-notebookdata-analysis

Python: how to build a text file for loading data?


I'm new to Python, and I am following this guide to implement a linear regression http://nbviewer.jupyter.org/github/jdwittenauer/ipython-notebooks/blob/master/notebooks/ml/ML-Exercise1.ipynb

Basically I am on the step where I need to build a data set to import it into Python

enter image description here

I have created a text file with two columns, each data is separated by a tab

enter image description here

However, this is what I get

enter image description here

I looked around online and it seems that the tab is the delimiter. What am I doing wrong? How can I build this text file?


Solution

  • I would advise using the official documentation instead of "looking around online" - if you check the pandas read_csv() documentation, it lists (at the very top) the default values of each argument. The default value of the sep (separator) argument is ", ". So just change your call to pd.read_csv() to add sep='\t'.