我在Excel中的每一列的每一行都有一个包含许多句子的列表。我有3个或更多的专栏有这样的句子。其中有一些常见的句子。有没有可能创建一个脚本来创建一个维恩图,并获得所有这些图之间的公共关系。
例如:这些是列中的句子。类似地,有不同的列。
来自癌症的血淋巴细胞
病人的外周血淋巴细胞
卵巢tumor_Grade III
腹膜tumor_Grade IV
激素抵抗PCA
可以用python编写脚本吗?
发布于 2009-10-02 18:43:35
这是我对这个问题的解释。
提供数据文件z.csv (将数据从excel导出为csv文件)
"Blood lymphocytes from cancer","Blood lymphocytes from sausages","Ovarian tumor_Grade III"
"Blood lymphocytes from patients","Ovarian tumor_Grade III","Peritoneum tumor_Grade IV"
"Ovarian tumor_Grade III","Peritoneum tumor_Grade IV","Hormone resistant PCA"
"Peritoneum tumor_Grade XV","Hormone resistant PCA","Blood lymphocytes from cancer"
"Hormone resistant PCA",,"Blood lymphocytes from patients"此程序查找所有列中共有的句子
import csv
# Open the csv file
rows = csv.reader(open("z.csv"))
# A list of 3 sets of sentences
results = [set(), set(), set()]
# Read the csv file into the 3 sets
for row in rows:
for i, data in enumerate(row):
results[i].add(data)
# Work out the sentences common to all rows
intersection = results[0]
for result in results[1:]:
intersection = intersection.intersection(result)
print "Common to all rows :-"
for data in intersection:
print data它会打印出这个答案
Common to all rows :-
Hormone resistant PCA
Ovarian tumor_Grade III不是100%确定这就是你要找的,但希望它能让你开始!
它可以很容易地推广到您喜欢的任意多个列,但我不想让它变得更复杂
发布于 2009-10-02 18:02:58
你的问题不完全清楚,所以我可能误解了你要找的是什么。
维恩图只是几个简单的集合操作。Python在Set数据类型中内置了这些东西。基本上,取你的两组项目并使用集合操作(例如,使用intersection查找公共项目)。
要读取数据,最好的方法可能是将文件保存为CSV格式,然后使用string split方法解析它。
https://stackoverflow.com/questions/1510972
复制相似问题