[数据分析]Pandas自测20题
Pandas 是用 Python 进行数据分析时最常用也是最强大的工具库。今天我们通过习题的形式整理了 pandas 中一些比较基础的常用操作。如果你是位 Pandas 新手,不妨通过此练习检验一下自己对基础的掌握情况;如果你是高手,欢迎留言给出与答案的不同解法。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))作者:刘早起早起
来源:早起Python
_往期文章推荐_
评论
