-1

designing an application I am looking for the best datastructure that should be used for passing 2D arrays between pure functions.

I would like them to be, by decreasing order of preference:

  • immutable
  • preferably from the native Python library
  • easily converted to Pandas Dataframe which will be used in most (but not all) functions
  • enabling fast execution (read) times.

Right now I am leaning towards tuple of tuples:

data=(("header a", "header b", "header c"), (1, 2, 3), (2, 3, 5))

but the idea of converting them to pandas dataframe like this:

df = pd.DataFrame(data=data[1:], columns=data[0])

does not quite feel the most Pythonic.

What would be the best "There should be one-- and preferably only one --obvious way to do it."?

martineau
  • 119,623
  • 25
  • 170
  • 301
Lionel Hamayon
  • 1,240
  • 15
  • 25

1 Answers1

1

Use immutable numpy arrays.

Immutable, fast, de facto standard python library for numeric arrays, works well with Pandas...

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28