I have modified my code and commented it for posting purposes, i'm new to numpy and can't figure out why it's not letting me plot this, it's an array of correctly formatted dates vs floats.
If anyone could give any advice it would be really appreciated
import datetime as dt
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import io
#----------------------------------------------------------
#Takes JSON data from online source and saves to .csv
URL_LTC = 'http://cryptocoincharts.info/fast/period.php?pair=LTC-USD&market=bitfinex&time=alltime&resolution=1d'
URL_BTC = 'http://cryptocoincharts.info/fast/period.php?pair=BTC-USD&market=bitfinex&time=alltime&resolution=1d'
data_LTC = pd.read_json(URL_LTC)
data_BTC = pd.read_json(URL_BTC)
data_BTC.to_csv('BTC_USD_PANDAS.csv')
data_LTC.to_csv('LTC_USD_PANDAS.csv')
#----------------------------------------------------------
#reads in data from csv
df_BTC = pd.read_csv('BTC_USD_PANDAS.csv',parse_dates=[0], dayfirst=True)
df_LTC = pd.read_csv('LTC_USD_PANDAS.csv',parse_dates=[0], dayfirst=True)
# turn into a numpy data array
BTC_data = df_BTC.values
LTC_data = df_LTC.values
#select the colums
offset = 6 #LTC starts 6 days before BTC
BTC_prices = BTC_data[1:269, 5:6]
LTC_prices = LTC_data[1+offset:269+offset, 5:6]
dates = BTC_data[1:269, 1:2]
#concatenate arrays
prices = np.hstack((BTC_prices,LTC_prices))
#plot data
plt.clf()
plt.plot(dates, prices)
plt.legend(['BTC','LTC'])
plt.ylabel('Close')
plt.xlabel('Date')
plt.savefig('BTC_LTC.pdf', format='pdf')
Results in this error (shortened version):
File "C:\Python27\lib\site-packages\matplotlib\lines.py", line 575, in recache
x = np.asarray(xconv, np.float_)
File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 462, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: invalid literal for float(): 2014-08-19 00
[Finished in 1.6s with exit code 1]
2014-08-19 00isn't and cannot be coerced into a float. What are the dtypes ofdateshere? Also post some data that reproduces the error