2016-11-20 72 views
2

我想解析來自finviz報價資料頁的刮取數據。我想我可以使用熊貓的數據透視表機制來獲得我需要的輸出,但從未使用數據透視表,因此我不確定是否或如何格式化輸出。格式數據透視表與偶列作爲列名

我收到的表格如下。我希望每個偶數列號都是輸出表的列標題。由於有72個值,所以以一行和72列結束數據幀。除非任何人都可以推薦更好的輸出結果以及如何訪問這些值?

0 1 2 3 4 5 6 7 8 9 10 11 
0 Index S&P 500 P/E 23.06 EPS (ttm) 3.15 Insider Own 0.20% Shs Outstand 1.01B Perf Week 3.94% 
1 Market Cap 73.24B Forward P/E 21.29 EPS next Y 3.41 Insider Trans -34.81% Shs Float 996.66M Perf Month 4.85% 
2 Income 3.21B PEG 2.31 EPS next Q 0.81 Inst Own 89.30% Short Float 2.05% Perf Quarter 4.47% 
3 Sales 13.15B P/S 5.57 EPS this Y 9.70% Inst Trans 0.42% Short Ratio 4.21 Perf Half Y 25.19% 
4 Book/sh 10.26 P/B 7.08 EPS next Y 7.88% ROA 20.10% Target Price 74.34 Perf Year 28.65% 
5 Cash/sh 3.11 P/C 23.35 EPS next 5Y 10.00% ROE 32.10% 52W Range 45.51 - 72.28 Perf YTD 36.02% 
6 Dividend 2 P/FCF 31.29 EPS past 5Y 1.50% ROI 21.60% 52W High 0.44% Beta 1.26 
7 Dividend % 2.75% Quick Ratio 2.5 Sales past 5Y -1.40% Gross Margin 60.70% 52W Low 59.54% ATR 1.34 
8 Employees 29977 Current Ratio 3.3 Sales Q/Q 7.20% Oper. Margin 35.20% RSI (14) 67.26 Volatility 1.65% 1.93% 
9 Optionable Yes Debt/Eq 0.35 EPS Q/Q 23.80% Profit Margin 24.40% Rel Volume 1.13 Prev Close 72.08 
10 Shortable Yes LT Debt/Eq 0.29 Earnings Oct 26 AMC Payout 47.70% Avg Volume 4.84M Price 72.6 
11 Recom 2.5 SMA20 3.86% SMA50 4.97% SMA200 16.49% Volume 5476883 Change 0.72% 

我知道的格式很難看,所以 enter image description here

回答

3

嘗試重塑

d1 = pd.DataFrame(df.values.reshape(-1, 2), columns=['key', 'value']) 
d1.set_index('key').T 
+0

稍後會嘗試謝謝! – mobone

+0

是的,這將工作。謝謝 – mobone