python交并补_交并补操作.py

import pandas as pd

import numpy as np

from matplotlib import pyplot as plt

from matplotlib_venn import venn2

'''tt = pd.read_excel("E:/111.xlsx")

print(tt.isnull())

bb = tt.dropna()

print(bb)'''

'''a = pd.read_table("C:/Users/hasee/Desktop/生物信息/final/EP/0.txt")

b = a.loc[:, ["gene_name"]]

c = pd.read_table("C:/Users/hasee/Desktop/生物信息/final/EP/2.txt")

d = c.loc[:, ["gene_name"]]

result_inner = pd.merge(b,d,how='inner') #交集 is

result_outer = pd.merge(b,d,how='outer')

cs1 = b.append(d)

bsc = cs1.drop_duplicates()

cs2 = d.append(b)

dsc = cs2.drop_duplicates()

print(bsc)

print(dsc)

bsc.to_excel("C:/Users/hasee/Desktop/生物信息/final/work.xlsx",sheet_name= "1",index=False)'''

for i in range(0,16):

a = pd.read_table("C:/Users/hasee/Desktop/生物信息/final/EP/"+str(i)+".txt")

b = a.loc[:, ["gene_name"]]

lista = b["gene_name"].values.tolist()

for t in range(0,16):

ts = "%t"

c = pd.read_table("C:/Users/hasee/Desktop/生物信息/final/ME/" + str(t) + ".txt")

d = c.loc[:, ["gene_name"]]

listd= d["gene_name"].values.tolist()

writer = pd.ExcelWriter("C://Users//hasee//Desktop//生物信息//final//work"+str(i)+str(t)+".xlsx")

intsec = pd.merge(b, d, how='inner') # intersection

intsec.to_excel(writer, sheet_name="intsec(EP"+str(t)+"ME"+str(t), index=False)

us = pd.merge(b, d, how='outer')#union set

fa = us.append(d)

print(fa)

fa = fa.drop_duplicates(subset =["gene_name"],keep=False) # a supplementary set drop_duplicates(subset=['name', 'age', 'sex'],keep=False

fb = us.append(b)

fb = fb.drop_duplicates(subset=["gene_name"], keep=False) # b supplementary set

fa.to_excel(writer, sheet_name="supleEP("+str(t)+"ME"+str(t)+")", index=False)

fb.to_excel(writer, sheet_name="supleME("+str(t)+"ME"+str(t)+")", index=False)

venn2(subsets = [set(lista),set(listd)],set_labels = ("EP","ME"),set_colors=("r","g"))

plt.savefig("C:/Users/hasee/Desktop/生物信息/final/"+str(i)+"&"+str(t)+".png")

plt.close()

writer.save()

writer.close()

print(i)

'''for t in range(0,16):

c = pd.read_table("C:/Users/hasee/Desktop/生物信息/final/ME/" + t + ".txt")

d = c.loc[:, ["gene_name"]]

intsec = pd.merge(b, d, how='inner') # intersection

intsec.to_excel("C:/Users/hasee/Desktop/生物信息/final/work.xlsx", sheet_name="1", index=1)

cs1 = b.append(d)

cs2 = d.append(b)

bsc = cs1.drop_duplicates() # a supplementary set

dsc = cs2.drop_duplicates() # b supplementary set

bsc.to_excel("C:/Users/hasee/Desktop/生物信息/final/work.xlsx", sheet_name="1", index=2)

dsc.to_excel("C:/Users/hasee/Desktop/生物信息/final/work.xlsx", sheet_name="1", index=1)

#数组里面,要取出一个东西,index,[]

#print()'''

'''df1 = pd.DataFrame([['a', 10, '男'],

['b', 11, '男'],

['c', 11, '女'],

['a', 10, '女'],

['c', 11, '男']],

columns=['name', 'age', 'sex'])

df2 = pd.DataFrame([['a', 10, '男'],

['b', 11, '男']],

columns=['name', 'age', 'sex'])

result_inner = pd.merge(df1,df2,how='inner',keep = ["age"])

result_outer = pd.merge(df1,df2,how='outer')

df3 = df1.append(df2)

df3 = df3.drop_duplicates(subset=['name', 'age', 'sex'],keep=False)

print(result_inner)

print(result_outer)

print(df3)'''

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值