點我下載:song_rank2.csv
import pandas as pd
with open('data/song_rank2.csv') as f:
p2 = pd.read_csv(f)
p2
#single augr.: the labels of indexs # including both
#single
#list
#slice
p2.loc[0] #single
Rank 1
Hits 98318
Song 青空未來
Co 否
Artist 五月天 阿信
Date 2021-07-28
Url https://www.kkbox.com/tw/tc/song/d6L00KOUN.rUv...
Name: 0, dtype: object
l=[0,1]
p2.loc[l] #list
p2.loc[0:1] #slice
p2.loc[0:,"Artist"]
0 五月天 阿信
1 魏嘉瑩, 魏如昀
2 陳芳語 , 茄子蛋
3 蕭敬騰, 馬佳
4 吳汶芳
5 琳誼 Ring, 許富凱
6 張語噥
7 Ray 黃霆睿
8 飛兒樂團
9 摩登兄弟劉宇寧
10 五月天 阿信
11 五月天 阿信
12 魏嘉瑩, 魏如昀
13 陳芳語 , 茄子蛋
Name: Artist, dtype: object
p2.loc[0:1,'Artist']
0 五月天 阿信
1 魏嘉瑩, 魏如昀
Name: Artist, dtype: object
p2.loc[0:1,'Artist2']=50
p2
art1 = p2.Artist.str.split(',', expand=True)[0]
art2 = p2.Artist.str.split(',', expand=True)[1]
p2.loc[0:,'art1']=art1
p2.loc[0:,'art2']=art2
p2
p2.columns
Index(['Rank', 'Hits', 'Song', 'Co', 'Artist', 'Date', 'Url', 'Artist2',
'art1', 'art2'],
dtype='object')
new_l = ['Rank', 'Hits', 'Song', 'Co', 'Artist',
'art1', 'art2', 'Date', 'Url', 'Artist2']
p2[new_l]
#augr.: the indexs # end excluded
p2.iloc[0:1]
p2.loc[0:1]