2017-09-23 99 views
0

我有一個來自csv文件的數據幀。其中一列的價值如下。列名是'位置'。DataFrame列拆分(從CSV文件導入數據)

(36.204824,138.252924)

(35.86166,104.195397)

(49.81749199999999,15.472962)

(41.87194,12.56738)

(37.09024,-95.712891)

我想將列分成兩列,如下所示:

6.204824 138.252924

35.86166 104.195397

49.81749199999999 15.472962

41.87194 12.56738

37.09024 95.712891

我試圖DF [ 'LAT'],DF [ '長'] =拉鍊( * df.location)

我得到了以下錯誤:

類型錯誤:壓縮參數#362必須支持迭代

+0

是這個'(36.204824,138.252924)'string? – RomanPerekhrest

+0

@RomanPerekhrest是因爲我從csv文件導入數據?它是元組。 –

回答

0

讓我們嘗試applypd.Series

設置:

df = pd.DataFrame({'location':[(1,2),(3,4),(5,6)]}) 
print(df) 

    location 
0 (1, 2) 
1 (3, 4) 
2 (5, 6) 

使用applypd.series

df2 = pd.DataFrame() 
df2[['lat','long']] = df.location.apply(pd.Series) 

print(df2) 

輸出:

lat long 
0 1  2 
1 3  4 
2 5  6