2017-05-03 49 views
0

我是Python熊貓新手。在我的數據框中有一個名爲'helpful'的列,它有一個dtype 'o'。該列中的值與[2,5]相似。我需要提取2和5以便對它們執行操作。任何人都可以建議我如何做到這一點?使用dtype'o'從數據幀列提取值

+1

什麼是'打印(型(DF [ '有用'] IAT [0])。)'? – jezrael

回答

0
import pandas as pd 
df = pd.DataFrame({'helpful': {0: [2, 5], 1: [3, 6]}}) 
print(df) 
Out[742]: 
    helpful 
0 [2, 5] 
1 [3, 6] 

#access first row for column helpful 
df.helpful.values[0] 
Out[743]: [2, 5] 

#access first element of first row for column helpful 
df.helpful.values[0][0] 
Out[744]: 2 
0

嘗試:

df = pd.DataFrame({'helpful': ['2,5','4,0','7,3']}) 

for val in df.helpful.apply(lambda x: x.split(',')): 
    print val[0] 
    print val[1] 
    print '_'*3