Importing Data Into Python

We have to import the data into Python before analyzing it. This is usually the first step. One of the best ways to import data into Python is pandas.

First, start Spyder. Then type the following (don't forget to replace file location with your own file location).

import pandas as pd

lecture1 = pd.read_csv("D:\sample_xy.csv")
print(lecture1)

There it is. You just transformed a csv file to a dataframe object. If you don't like the way print command produces your table just double click lecture1 in the variable explorer window as shown below.

One of the differences between Python (or rather pandas) and SAS is that the data type of each column is determined by all rows in Python by default whereas it is by the first 20 rows in SAS (which you can change of course). To see the data type of each column:

lecture1.dtypes

>> x int64
>> y int64
>> dtype: int64