2016-11-15 64 views
0

當我嘗試執行file.write()csv文件中的輸出未完成時,我有更多的3000行數據,而我在文件中獲得的所有數據都是頂部和底部50行。我究竟做錯了什麼?如何將整個數據幀保存在csv文件中?

PS進出口編程:)相當新鮮

import pandas as pd 
import quandl 
import unicodecsv 

#getting stock data from Quandl API 
df = quandl.get("WIKI/GOOGL") 
#defining the columns I want to use 
df = df[['Adj. Open', 'Adj. High', 'Adj. Low', 'Adj. Close', 'Adj. Volume']] 
#creating new column and calculating using data from previously defined columns 
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low'])/df['Adj. Close'] * 100 

df = df[['Adj. Close', 'HL_PCT']] 
print(df) 

file = open('adjClosePCT.csv', 'w') 
file.write(str(df)) 

file.close() 
+2

嘗試['df.to_csv()'](HTTP:// pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html)。 –

回答

2

大熊貓內置to_csv應該做的工作:

df.to_csv('adjClosePCT.csv') 
相關問題