- 更改列名:(按照列表新旧字典格式更改)
df.rename(columns={'name':'school'},inplace=True)
- 多表合并(列不一样时,按照列名为key,合并方式可以通过参数修改,对应sql的形式)
df_norm = pd.merge(df_1,df_2,how = 'inner',on = 'school')
用并集的形式合并df_data_bingji = pd.concat([df,diff_data],axis =0)
当两个表列的形式相同时,可以直接用append方法直接插入,res_bingji = diff_data.append(df)
- 按照两列条件来选取数据
df_norm_all = df_norm.loc[df_norm['school']==df_norm['search_name']]
- 去掉字符串中的()
def del_bracket(str): str = str.replace('(','').replace(')','') return str
- 对某一列执行去掉特殊字符操作
res_bingji['other_name'] = res_bingji['other_name'].apply(del_bracket)
- 去掉某一列中不想要的数据
s = pd.Series('南京审计大学') df_not_get = df[~df['highest_school'].isin(s)]
- 按照某些列数据去掉列值为nan的整行数据
df.dropna(axis=0,how = 'all',subset=['category','property'],inplace=True)
- 按某一列的值进行去重
df_stand_name_guanxi.drop_duplicates(subset=['stand_name'],keep='first',inplace=True)
pandas 常用命令
最新推荐文章于 2025-05-10 16:56:32 发布