如何找出pandas数据框列中的每个元素? 我想做这样的事情:
for item in column:
print("usercode = " + item)
# OUTPUT:
# usercode = key00
# usercode = key01
# usercode = key02
数据框如下:
USERCODES NAMES
0 key00 ab00
1 key01 cd01
2 key02 ef02
答案 0 :(得分:0)
对于列中的每个值,使用Series.apply
:
def f(item):
print("usercode = " + item)
df['NAMES'].apply(f)
usercode = ab00
usercode = cd01
usercode = ef02
一行:
df['NAMES'].apply(lambda item: print("usercode = " + item))
usercode = ab00
usercode = cd01
usercode = ef02
Simpliest:
for item in df['NAMES']:
print("usercode = " + item)
usercode = ab00
usercode = cd01
usercode = ef02