when I try to do file.write() the output in the csv file is not complete, I have more then 3000 rows of data and all I get in the file is top and bottom 50 lines. What am I doing wrong?
PS Im fairly fresh in programming :)
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()
内置to_csv
应该可以完成以下工作:
df.to_csv('adjClosePCT.csv')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.