Skip to content

Instantly share code, notes, and snippets.

@wesm
Created November 29, 2018 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesm/2ebe0ca2461d1ecfba6185777238ad1f to your computer and use it in GitHub Desktop.
Save wesm/2ebe0ca2461d1ecfba6185777238ad1f to your computer and use it in GitHub Desktop.
In [1]: paste
import pandas as pd
import feather
data = {'date': ['2014-05-01 18:47:05.069722', '2014-05-01 18:47:05.119994',
'2014-05-02 18:47:05.178768', '2014-05-02 18:47:05.230071',
'2014-05-02 18:47:05.230071', '2014-05-02 18:47:05.280592']}
df = pd.DataFrame(data, columns = ['date'])
df['date'] = pd.to_datetime(df['date']).dt.date
## -- End pasted text --
In [2]: df
Out[2]:
date
0 2014-05-01
1 2014-05-01
2 2014-05-02
3 2014-05-02
4 2014-05-02
5 2014-05-02
In [3]: df['date']
Out[3]:
0 2014-05-01
1 2014-05-01
2 2014-05-02
3 2014-05-02
4 2014-05-02
5 2014-05-02
Name: date, dtype: object
In [4]: df['date'][0]
Out[4]: datetime.date(2014, 5, 1)
In [5]: df.to_feather('foo.feather')
In [6]: import pyarrow as pa
In [7]: pa.feather.FeatherReader?
Init signature: pa.feather.FeatherReader(source)
Docstring: <no docstring>
File: ~/code/arrow/python/pyarrow/feather.py
Type: type
In [8]: reader = pa.feather.FeatherReader('foo.feather')
In [9]: t = reader.read_table()
In [10]: t
Out[10]:
pyarrow.Table
date: date32[day]
In [11]: t.to_pandas()
Out[11]:
date
0 2014-05-01
1 2014-05-01
2 2014-05-02
3 2014-05-02
4 2014-05-02
5 2014-05-02
In [12]: t.to_pandas().dtypes
Out[12]:
date datetime64[ns]
dtype: object
In [13]: t.to_pandas()
Out[13]:
date
0 2014-05-01
1 2014-05-01
2 2014-05-02
3 2014-05-02
4 2014-05-02
5 2014-05-02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment