2017-03-29 44 views
1

各列說我有一個數據幀df1與一羣列:下探使用ILOC

Index(['Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close', 'log_return', 
    'close_open', 'Daily_Change', '30_Avg_Vol', '20_Avg_Vol', '15_Avg_Vol', 
    '9_Avg_Vol', 'changed', 'p_changed', '5days', '7days', 
    '7days_10daysAvg', '5_7days_Avg', '-2_before', '-1_before', '0_before', 
    '1_before', '2_before', '3_before', '4_before', '5_before', '6_before', 
    'Bullish'], 
    dtype='object') 

我想創建一個新的數據幀,保持一些列的和下降等。我想繼續列0-13,13-19,19-28(使用偏移量符號)

我想這些

x2 =df.iloc[:-5, [0:13,13:19, 19:28 ]]  # meant to edit 13:19 in this line 
x2 =df.iloc[:-5, [[0:13],[13:19], [19:28 ]] 

,但沒有運氣的變化。我得到一個syntaxerror

回答

2

使用np.r_

df.iloc[:-5, np.r_[0:13, 13:19, 19:28]] 
+1

這工作。謝謝!我打算省略專欄13:19,哈哈。 – Moondra