Thursday, February 21, 2019

How do I read a tabular data file into pandas


Untitled
In [1]:
import pandas as pd
In [4]:
orders = pd.read_table('http://bit.ly/chiporders')
In [5]:
orders.head()
Out[5]:
order_id quantity item_name choice_description item_price
0 1 1 Chips and Fresh Tomato Salsa NaN $2.39
1 1 1 Izze [Clementine] $3.39
2 1 1 Nantucket Nectar [Apple] $3.39
3 1 1 Chips and Tomatillo-Green Chili Salsa NaN $2.39
4 2 2 Chicken Bowl [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98
In [14]:
user_cols = ['user_id', 'age', 'gender', 'occupation','zip_code']
users = pd.read_table('http://bit.ly/movieusers', sep='|', header= None, names= user_cols)
In [15]:
users.tail()
Out[15]:
user_id age gender occupation zip_code
938 939 26 F student 33319
939 940 32 M administrator 02215
940 941 20 M student 97229
941 942 48 F librarian 78209
942 943 22 M student 77841
In [ ]:
 

No comments:

Post a Comment