ameyazing
ameyazing

Reputation: 423

Dump quandl data to file

I'm using the Quandl Python module to get data.

I'm fetching the data using:

quandl.ApiConfig.api_key = '******************'
df = quandl.get('WIKI/GOOGL')

This seems to work fine. If I try to print the data (using print(df)) on screen it shows me something like (truncated):

2004-09-29   30516400.0  
2004-09-30   13758000.0  
...                 ...  
2017-05-26    1622807.0  
2017-05-30    1511472.0  

[3245 rows x 12 columns]

So, I assume it is able to fetch the data. Now, I'm trying to dump this data to file using following code:

thefile = open('data.txt', 'w')
for item in df:
    thefile.write("%s\n" % item)

This is what I get in the file:

Open
High
Low
Close
Volume
Ex-Dividend
Split Ratio
Adj. Open
Adj. High
Adj. Low
Adj. Close
Adj. Volume

This seems to be the metadata or fields names of the actual data.

What I want to do is dump this data to a file so that I can study it manually before applying any algorithm on it. I know there are other ways to look at data (Excel, web api, etc.), but this is more 'inline' for me. Can you please tell me what I'm doing wrong and how to dump the data to file from the Python code?

Upvotes: 2

Views: 1226

Answers (1)

ameyazing
ameyazing

Reputation: 423

Problem solved. In above code, df is not a Python list. It is a pandas dataframe object. calling .to_csv() on it allows you to save the data in df object to a csv file. Very close to what I wanted.

Upvotes: 2

Related Questions