import pandas as pd
data = pd.read_csv('traj2_Binarization.csv', sep=",", index_col="NAME")
for index, row in data.iterrows():
print(row)
-----results------ RUNX3 0 ROGDI 0 FSTL3 0 MOCOS 0 PDCD7 1 MYO15A 0 MYO9B 0 MAP1LC3A 0 TBC1D19 0 ASIC1 0 RAP1A 0 ARAP3 0 IQSEC2 0 HIVEP3 0
Here, how can I make the results converted to below?
RUNX3 = False
ROGDI = False
FSTL3 = False
MOCOS = False
PDCD7 = True
.
.
.
最佳答案
除了 @jezrael 的回答之外,如果版本低于 3.6:
for index, row in data.iterrows():
print('%s = %s'%(index,bool(row['whatever is the column'])))
或者:
for index, row in data.iterrows():
print('{0} = {1}'.format(index,bool(row['whatever is the column'])))
或者:
for index, row in data.iterrows():
print(index,'=',bool(row['whatever is the column']))
所有输出:
RUNX3 = False
ROGDI = False
FSTL3 = False
MOCOS = False
PDCD7 = True
MYO15A = False
MYO9B = False
MAP1LC3A = False
TBC1D19 = False
ASIC1 = False
RAP1A = False
ARAP3 = False
IQSEC2 = False
HIVEP3 = False
关于python - Pandas如何获取行的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53184739/