0
我有一個CSV文件中包含這樣的數據檢索行:如何從一個CSV文件中使用代碼字符串
我寫下代碼能夠檢索包含「激活」,在第二列的行「結果」:
數據:
No,Outcome,target,result
1,Active,PGS2,positive
2,inactive,IM2,negative
3,inactive,IGI,positive
4,Active,IIL,positive
5,Active,P53,negative
代碼:
new_file = open(my_file)
lines = new_file.readlines()
for line in lines:
if "Active" in line:
print line,
結果:
No,Outcome,target,result
1,Active,PGS2,positive
4,Active,IIL,positive
5,Active,P53,negative
我怎樣才能使用熊貓庫,這樣我可以,如果我檢索行後使用熊貓功能使代碼更短寫下這段代碼。
此外,此代碼不適合當您在「行」關鍵字相同的地方,因爲它可以檢索錯誤的行。預覽了一些帖子後,我發現「pandas」非常適合CSV處理庫。
哎再次感謝你有沒有喜歡pd.set_option任何函數(「display.max_rows」,無)」列也因爲同樣的問題,在我試圖pd.set_option列的情況下產生的( 'display.max_columns',None)但它不起作用 – 2014-08-29 10:57:30
您的意思是'max_colwidth'?在我之前給出的答案中有一個選項列表:http://stackoverflow.com/questions/21293536/list-of-pandas -options/21293562#21293562 – EdChum 2014-08-29 11:05:42
再次感謝你「pd.set_option('display.line_width',2000)」爲我工作 – 2014-08-29 11:29:50