1 Pandas Basic I
1 Pandas Basic I
1 2
SERIES: A PANDAS SERIES IS A ONE DATAFRAME: A PANDAS DATAFRAME IS
DIMENSIONAL DATA STRUCTURE (“A A TWO (OR MORE) DIMENSIONAL DATA
ONE DIMENSIONAL NDARRAY”) THAT STRUCTURE – BASICALLY A TABLE WITH
CAN STORE VALUES — AND FOR EVERY ROWS AND COLUMNS. THE COLUMNS
VALUE IT HOLDS A UNIQUE INDEX, HAVE NAMES AND THE ROWS HAVE
TOO. INDEXES.
Loading a .csv file into
a pandas DataFrame
Data sources:
1. Make csv file
2. Download csv file directly from
python script
3. Import .csv file
4. load the .csv data using the URL
directly
Buat file csv dengan data sebagai berikut:
animal,uniq_id,water_need
elephant,1001,500
elephant,1002,600
elephant,1003,550
tiger,1004,300
tiger,1005,320
tiger,1006,330
tiger,1007,290
tiger,1008,310
zebra,1009,200
1. Make .csv File zebra,1010,220
zebra,1011,240
zebra,1012,230
zebra,1013,220
zebra,1014,100
zebra,1015,80
lion,1016,420
lion,1017,600
lion,1018,500
lion,1019,390
kangaroo,1020,410
kangaroo,1021,430
kangaroo,1022,410
Save as zoo
Loading zoo.csv file
into a pandas Data
Frame
import pandas as pd
import numpy as np
pd.read_csv('zoo.csv', delimiter = ' , ')
You can download pandas_tutorial_read.csv from
http://46.101.230.157/dilan/pandas_tutorial_read.csv link
to your server and then load it to your Jupyter using wget module
.CSV File
dengan module Tuliskan alamat tempat data akan di download
Simpan di drive yang sama dengan script di download
wget
Check if pandas_tutorial_read.csv file downloaded to
your server
2. Print a Sample of
Your Dataframe
PRINT THE LAST FEW LINES
>>> article_read.tail()
2. Print a Sample of
Your Dataframe
PRINT FEW RANDOM LINES
>>> article_read.sample(5)
2. Print a Sample of
Your Dataframe
PRINT THE ‘country’ AND THE ‘user_id’ COLUMNS
ONLY
>>> article_read[['country', 'user_id']]
3. Select Specific
Columns of Your
Dataframe
CHANGE THE ORDER OF THE COLUMN NAMES
>>> article_read[['user_id', 'country']]
3. Select Specific
Columns of Your
Dataframe
3. Select Specific You can get a Series using any of these two
syntaxes (and selecting only one column):
Columns of Your >>> article_read.user_id
Dataframe >>> article_read['user_id']
Sometimes (especially in
predictive analytics projects), you
want to get Series objects instead
of DataFrames.
See a list of only the users who came from the ‘SEO’ source. In this
case you have to filter for the ‘SEO’ value in the ‘source’ column: