2017-09-25 104 views
-6

如何找出熊貓數據框的列中存在的每個元素? 我願做這樣的事情:如何遍歷熊貓數據框列中的元素?

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 
+1

'對於i,排在df.iterrows():打印(行[ 'USERCODES'])' –

回答

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 
+0

是DF1數組? –

+0

不,它是DataFrame。 – jezrael

+0

我認爲之前的回答是正確的'df ['USERCODES']。radd('usercode =')'或''usercode ='+ df ['USERCODES']' – Dark