AES AIG AIV
1/3/2008 1
2/6/2008 1
2/11/2008 1 1
!cat dd.csv
,AES,AIG,AIV
1/3/2008 16:00,,1,
2/6/2008 16:00,1,,
2/11/2008 16:00,1,,1
import pandas as pd
import numpy as np
s_input_file = 'dd1.csv'
df = pd.read_csv(s_input_file, sep=',',header=0) #orders.csv
def getcell(x):
if (x==1.0 and df.ix[x, df.ix[x]==1.0].values[0]==1.0):
print x, df.ix[x, df.ix[x]==1.0].index[0], df.ix[x][0]
df.applymap(getcell)
得到正确的 4 个输出计数,但没有引用正确的索引行和列“如何打印单元格 == 1 的行索引和列?”
1.0 AES 2/6/2008 16:00
1.0 AES 2/6/2008 16:00
1.0 AES 2/6/2008 16:00
1.0 AES 2/6/2008 16:00
我怎样才能得到这样的预期输出:
1/3/2008, AIG
2/6/2008, AES
2/11/2008, AES
2/11/2008, AIG