0

Let say I have an array:

array([('a', 1), ('b', 2), ('c', 3), ...,
       ('x', 24), ('y', 25), ('z', 26)],
      dtype=object)

How do I split it into 2 columns as in 'alphabet' and 'order'? Much appreciated!

Henry Li
  • 46
  • 4
  • 2
    [`pd.DataFrame.from_records`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_records.html) – Ch3steR Dec 12 '20 at 07:31
  • A simple `pd.DataFrame(arr)` would also work. – Mayank Porwal Dec 12 '20 at 08:28
  • Assuming the array `shape` is (n,2), then `arr[:,0]` will be a 1d array of the letters, and `arr[:,1}` the numbers. You could also apply `astype` to change them to string and integer dtypes. This is basic `numpy` coding. – hpaulj Dec 12 '20 at 16:53

0 Answers0