[數(shù)據(jù)分析]Pandas自測(cè)20題
Pandas 是用 Python 進(jìn)行數(shù)據(jù)分析時(shí)最常用也是最強(qiáng)大的工具庫(kù)。今天我們通過(guò)習(xí)題的形式整理了 pandas 中一些比較基礎(chǔ)的常用操作。如果你是位 Pandas 新手,不妨通過(guò)此練習(xí)檢驗(yàn)一下自己對(duì)基礎(chǔ)的掌握情況;如果你是高手,歡迎留言給出與答案的不同解法。Here we go!
data = {"grammer":["Python","C","Java","GO",np.nan,"SQL","PHP","Python"],
???????"score":[1,2,np.nan,4,5,6,7,10]}
df?= pd.DataFrame(data)grammer??score
0 Python????1.0
7 Python???10.0result=df[df['grammer'].str.contains("Python")]Index(['grammer', 'score'], dtype='object')df.columnsdf.rename(columns={'score':'popularity'}, inplace = True)df['grammer'].value_counts()df['popularity'] = df['popularity'].fillna(df['popularity'].interpolate())df[df['popularity']?> 3]df.drop_duplicates(['grammer'])df['popularity'].mean()df['grammer'].to_list()df.to_excel('filename.xlsx')df.shapedf[(df['popularity']?> 3) &?(df['popularity'] < 7)]temp = df['popularity']
df.drop(labels=['popularity'], axis=1,inplace = True)
df.insert(0, 'popularity', temp)df[df['popularity'] == df['popularity'].max()]df.tail()df?= df.drop(labels=0)row={'grammer':'Perl','popularity':6.6}
df = df.append(row,ignore_index=True)df.sort_values("popularity",inplace=True)df['grammer'].map(lambda x: len(x))作者:劉早起早起?
來(lái)源:早起Python
_往期文章推薦_
評(píng)論
圖片
表情
