Skip to main content
Fixed the weird syntax highlighting (as a result, the diff looks more extensive than it really is - use view "Side-by-side Markdown" to compare).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

I did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 
In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

I did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

I did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

Active reading. Used a more direct cross reference (as user names can change at any time).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

DidI did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChumthanks EdChum!)

Did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

I did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

added 76 characters in body
Source Link
tegan
  • 2.3k
  • 2
  • 17
  • 18

Did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [23][1]: %timeit list(dataframe.columns.values)[column for column in df] 1000001000 loops, best of 3: 581.056 µs per loop In [24][2]: %timeit dataframedf.columns.values.tolist() 10000010000 loops, best of 3: 216.341 µs per loop In [25][3]: %timeit list(dataframedf) 10000010000 loops, best of 3: 744.489 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

Did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [23]: %timeit list(dataframe.columns.values) 100000 loops, best of 3: 5.05 µs per loop In [24]: %timeit dataframe.columns.values.tolist() 100000 loops, best of 3: 2.34 µs per loop In [25]: %timeit list(dataframe) 100000 loops, best of 3: 7.48 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

Did some quick tests, and perhaps unsurprisingly the built-in version using dataframe.columns.values.tolist() is the fastest:

In [1]: %timeit [column for column in df] 1000 loops, best of 3: 81.6 µs per loop In [2]: %timeit df.columns.values.tolist() 10000 loops, best of 3: 16.1 µs per loop In [3]: %timeit list(df) 10000 loops, best of 3: 44.9 µs per loop In [4]: % timeit list(df.columns.values) 10000 loops, best of 3: 38.4 µs per loop 

(I still really like the list(dataframe) though, so thanks EdChum!)

Source Link
tegan
  • 2.3k
  • 2
  • 17
  • 18
Loading