Advertisement
Guest User

stellographer_dataframe

a guest
May 17th, 2015
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.61 KB | None | 0 0
  1. In [1]: from astropy.io import fits
  2.  
  3. In [2]: import pandas as pd
  4.  
  5. In [3]: d = fits.getdata('pandas.fit')
  6.  
  7. In [4]: d
  8. Out[4]:
  9. FITS_rec([(293.672708, 48.155611), (219.2110132, 33.303077000000002),
  10.        (92.133392000000001, 14.653280000000001),
  11.        (351.31415700000002, 15.950782), (109.3717, 22.214390000000002),
  12.        (109.35231, 30.833805000000002),
  13.        (121.80719000000001, 4.4392250000000004),
  14.        (135.4007, 30.848746999999999), (102.52856, 38.827131999999999),
  15.        (33.579945000000002, 44.581505)],
  16.       dtype=[('ra', '>f8'), ('de', '>f8')])
  17.  
  18. In [5]: np.array(d)
  19. Out[5]:
  20. array([(293.672708, 48.155611), (219.2110132, 33.303077),
  21.        (92.133392, 14.65328), (351.314157, 15.950782),
  22.        (109.3717, 22.21439), (109.35231, 30.833805), (121.80719, 4.439225),
  23.        (135.4007, 30.848747), (102.52856, 38.827132),
  24.        (33.579945, 44.581505)],
  25.       dtype=[('ra', '>f8'), ('de', '>f8')])
  26.  
  27. In [6]: df = pd.DataFrame(np.array(d))
  28.  
  29. In [7]: df
  30. Out[7]:
  31.            ra         de
  32. 0  293.672708  48.155611
  33. 1  219.211013  33.303077
  34. 2   92.133392  14.653280
  35. 3  351.314157  15.950782
  36. 4  109.371700  22.214390
  37. 5  109.352310  30.833805
  38. 6  121.807190   4.439225
  39. 7  135.400700  30.848747
  40. 8  102.528560  38.827132
  41. 9   33.579945  44.581505
  42.  
  43. In [8]: df[df['ra'] > 200]
  44. ---------------------------------------------------------------------------
  45. ValueError                                Traceback (most recent call last)
  46. <ipython-input-8-977482d317cf> in <module>()
  47. ----> 1 df[df['ra'] > 200]
  48.  
  49. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in __getitem__(self, key)
  50.    1772         if isinstance(key, (Series, np.ndarray, Index, list)):
  51.    1773             # either boolean or fancy integer index
  52. -> 1774             return self._getitem_array(key)
  53.    1775         elif isinstance(key, DataFrame):
  54.    1776             return self._getitem_frame(key)
  55.  
  56. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in _getitem_array(self, key)
  57.    1814             key = _check_bool_indexer(self.index, key)
  58.    1815             indexer = key.nonzero()[0]
  59. -> 1816             return self.take(indexer, axis=0, convert=False)
  60.    1817         else:
  61.    1818             indexer = self.ix._convert_to_indexer(key, axis=1)
  62.  
  63. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/generic.pyc in take(self, indices, axis, convert, is_copy)
  64.    1320         new_data = self._data.take(indices,
  65.    1321                                    axis=self._get_block_manager_axis(axis),
  66. -> 1322                                    convert=True, verify=True)
  67.    1323         result = self._constructor(new_data).__finalize__(self)
  68.    1324
  69.  
  70. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.pyc in take(self, indexer, axis, verify, convert)
  71.    3311         new_labels = self.axes[axis].take(indexer)
  72.    3312         return self.reindex_indexer(new_axis=new_labels, indexer=indexer,
  73. -> 3313                                     axis=axis, allow_dups=True)
  74.    3314
  75.    3315     def merge(self, other, lsuffix='', rsuffix=''):
  76.  
  77. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.pyc in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy)
  78.    3200                                       fill_tuple=(fill_value if fill_value is not None else
  79.    3201                                                   blk.fill_value,))
  80. -> 3202                           for blk in self.blocks]
  81.    3203
  82.    3204         new_axes = list(self.axes)
  83.  
  84. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.pyc in take_nd(self, indexer, axis, new_mgr_locs, fill_tuple)
  85.     860             fill_value = fill_tuple[0]
  86.     861             new_values = com.take_nd(self.get_values(), indexer, axis=axis,
  87. --> 862                                      allow_fill=True, fill_value=fill_value)
  88.     863
  89.     864         if new_mgr_locs is None:
  90.  
  91. /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/common.pyc in take_nd(arr, indexer, axis, out, fill_value, mask_info, allow_fill)
  92.     817
  93.     818     indexer = _ensure_int64(indexer)
  94. --> 819     func(arr, indexer, out, fill_value)
  95.     820
  96.     821     if flip_order:
  97.  
  98. pandas/src/generated.pyx in pandas.algos.take_2d_axis1_float64_float64 (pandas/algos.c:95513)()
  99.  
  100. ValueError: Big-endian buffer not supported on little-endian compiler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement