df.drop(["column"],axis=1,inplace=True) #删除一列
df.dropna(axis=0)#去除空值所在行
df.dropna(subset=['A'])#对列去空值
df[ df['A'].notna() ] #剔除没有映射注释的列
df.drop_duplicates(subset=['column'], keep='first', inplace=True) #对列去重
df['new']=t2[['A','B']].astype(str).agg('_'.join, axis=1) #以下划线连接两列的内容到新列
"_".join(ndarray[0]) #以下划线连接数组里的所有元素,字符拼接
df['new'] = df["column"].str.split("-",expand=True)[1] #对column列的内容以短横线分割取第2个子串到new列
df['A'].str.replace('/','-')#将A列值中的"/"替换为"-"
df.index.name = None#去除索引列的列名
df['A'].apply(lambda x: format(x, '.2%')) #对列值取百分数
df.rename(columns={'A':'a', 'B':'b', 'C':'c'}, inplace = True)#批量重命名列名
df.astype({'col_A':'str',,'col_B':'float64'})#批量转换列数据类型
df.set_index("column") #设置索引列
df = df_1.join(df_2)#左合并数据框,空值填充为nan
df.fillna(0,inplace=True)#修改原对象填充空值为0
df.idxmax(axis=1)#返回一行的最大值对应的列名
df.max(axis=1)#返回一行的最大值
df.groupby(['cellN', 'geneID'])['UMICount'].sum().unstack()#从三元组统计表达矩阵
df[ ~(df['col_A'].str.find("subString") != -1) ]#去除col_A列包含子串"subString"的记录
df[ df['col_A'].str.find("subString") != -1 ]#返回col_A列包含子串"subString"的记录
df.to_csv( "file",sep='\t',mode='a',index=False,header=False)#以追加记录的方式写入文件
###判断两列的结果是否相等(行内列比较),新建一列返回判断结果,
df['bool'] = df.apply(lambda x : 1 if x['col_A'] == x['col_B'] else 0, axis=1)
df['bool'] = df.apply(lambda x : 1 if str(x['col_A']).find(str(x['col_B'])) != -1 else 0, axis=1)
df['bool'] = np.where(df['col_A'] == df['col_B'], 1, 0)
npList = list(set(df.to_numpy().reshape(-1))) #df转成一维List,narray to array to list
###
df['col_A'].value_counts(ascending=False) #列值统计
df.groupby(['col_A']).sort_values(ascending=False)
网友评论