In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('data/historical-data-extract.csv')
df.tail()
Out[2]:
Unnamed: 0
Date
Open
High
Low
Close
Volume
Market Cap
currency
symbol
560706
45
Oct 21, 2017
0.000661
0.000918
0.000605
0.000782
142870
-
Swisscoin
SIC
560707
46
Oct 20, 2017
0.000570
0.000784
0.000455
0.000782
139044
-
Swisscoin
SIC
560708
47
Oct 19, 2017
0.000503
0.000574
0.000395
0.000513
187487
-
Swisscoin
SIC
560709
48
Oct 18, 2017
0.000448
0.000940
0.000430
0.000503
531964
-
Swisscoin
SIC
560710
49
Oct 17, 2017
0.000504
0.000560
0.000391
0.000392
169334
-
Swisscoin
SIC
In [3]:
df = df.drop(columns=['Unnamed: 0'])
df = df.rename(columns={'Date': 'date', 'Open': 'open', 'High': 'high', 'Low': 'low',
'Close': 'close', 'Volume': 'volume', 'Market Cap': 'market_cap'})
df = df[['currency', 'symbol', 'date', 'open', 'high', 'low', 'close', 'volume', 'market_cap']]
df.head()
Out[3]:
currency
symbol
date
open
high
low
close
volume
market_cap
0
Bitcoin
BTC
Dec 13, 2017
17500.0
17653.1
16039.7
16408.2
12976900000
292900000000
1
Bitcoin
BTC
Dec 12, 2017
16919.8
17781.8
16571.6
17415.4
14603800000
283155000000
2
Bitcoin
BTC
Dec 11, 2017
15427.4
17513.9
15404.8
16936.8
12153900000
258147000000
3
Bitcoin
BTC
Dec 10, 2017
15168.4
15850.6
13226.6
15455.4
13433300000
253782000000
4
Bitcoin
BTC
Dec 09, 2017
16523.3
16783.0
13674.9
15178.2
13911300000
276415000000
In [7]:
df['date'] = pd.to_datetime(df['date'])
df.head()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/site-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
302 try:
--> 303 values, tz = tslib.datetime_to_datetime64(arg)
304 return DatetimeIndex._simple_new(values, name=name, tz=tz)
pandas/_libs/tslib.pyx in pandas._libs.tslib.datetime_to_datetime64()
TypeError: Unrecognized value type: <class 'str'>
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-7-8d385a03db79> in <module>()
----> 1 df['date'] = pd.to_datetime(df['date'])
2
3 df.head()
/usr/local/lib/python3.6/site-packages/pandas/core/tools/datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, box, format, exact, unit, infer_datetime_format, origin)
371 elif isinstance(arg, ABCSeries):
372 from pandas import Series
--> 373 values = _convert_listlike(arg._values, True, format)
374 result = Series(values, index=arg.index, name=arg.name)
375 elif isinstance(arg, (ABCDataFrame, MutableMapping)):
/usr/local/lib/python3.6/site-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
304 return DatetimeIndex._simple_new(values, name=name, tz=tz)
305 except (ValueError, TypeError):
--> 306 raise e
307
308 if arg is None:
/usr/local/lib/python3.6/site-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
292 dayfirst=dayfirst,
293 yearfirst=yearfirst,
--> 294 require_iso8601=require_iso8601
295 )
296
pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string()
/usr/local/lib/python3.6/site-packages/dateutil/parser.py in parse(timestr, parserinfo, **kwargs)
1180 return parser(parserinfo).parse(timestr, **kwargs)
1181 else:
-> 1182 return DEFAULTPARSER.parse(timestr, **kwargs)
1183
1184
/usr/local/lib/python3.6/site-packages/dateutil/parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
557
558 if res is None:
--> 559 raise ValueError("Unknown string format")
560
561 if len(res) == 0:
ValueError: Unknown string format
In [ ]:
df = df.sort_values(by=['date'])
df.head()
In [ ]:
Content source: myles/notebooks
Similar notebooks: