df = df[~df['Majority protein IDs'].str.contains('CON|REV', regex=True)] df = df.drop('Majority protein IDs', axis=1).join(df['Majority protein IDs'].str.split(';', expand=True).stack().reset_index(level=1, drop=True).rename('Majority protein IDs'))
def ab(df): return';'.join(df.values) newcolumns = df_merge.columns.tolist() newcolumns.remove('Majority protein IDs') newdf = df_merge.groupby(newcolumns)['Majority protein IDs'].apply(ab) ## 多行合并一行
for i in range(10): if i==5: break print('i=',i,end=',') else: print('success')#不输出 在for循环中含有break时则直接终止循环,并不会执行else子句。
for i in range(10): if i==5: continue print('i=',i,end=',') else: print('success')#输出
展平嵌套列表
1 2 3 4 5 6 7
newlist = [item for items in newlist for item in items] #或者您可以像这样从chain中使用itertools from itertools import chain newlist = list(chain(*newlist)) #或者您可以使用chain.from_iterable,其中无需解压缩列表 from itertools import chain newlist = list(chain.from_iterable(newlist)) #效率更高
生成requirements.txt
1
pipreqs ./ --encoding=utf-8 --force
单例
1 2 3 4 5 6 7
class Singleton(object): __instance = None
def __new__(cls, age, name): if not cls.__instance: cls.__instance = object.__new__(cls) return cls.__instance