Link to home
Start Free TrialLog in
Avatar of Lin Ruonan
Lin Ruonan

asked on

anaconda import csv file

Hello, I am a newbie in Python, and I am wondering how to import a dataset(csv file) to my Anaconda. Thanks in advance~
Avatar of Grze
Grze
Flag of Poland image

Hi Lin,

Since you mentioned Anaconda distribution, you should already have pandas package installed - which is all you need to deal with csv, excel, and many other data formats.

Using pandas is extremely easy. Here is an example of how to read in one of the classic datasets, titanic passenger data, directly from an online resource (note: this csv file is accessible as of 1 March 2018, note that some time in future this file might not be accessible any more, as I have grabbed it from a random git repository using a quick google search):

#import pandas
import pandas as pd 

# read any csv, including from online sources, into variable df (of type DataFrame)
df = pd.read_csv('https://raw.githubusercontent.com/pcsanwald/kaggle-titanic/master/train.csv')

# display first 5 rows of your data
df.head()

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.