On 27/04/18 15:50, zljubi...@gmail.com wrote:
> Hi,
> 
> I have pandas DataFrame with several columns. I have to pass all columns as 
> separate parameter to a function. 
> 
> Something like this if I have 4 columns.
> 
> f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 
> 2], df_piv.iloc[:, 3])
> 
> As number of columns varies, how to do it in the most efficient way?

You could get the DataFrame as a 2d array (df.values) and work from there:

  func(*df.values.T)

Of course, this is completely unreadable, and it has another problem: if
your columns have different types, this will cast some or all of your
columns to a different type.

It's probably clearer if you start with the column labels:

  func(*(df.loc[:,col] for col in df.columns))

or use df.items():

  func(*(values for col, values in df.items()))



-- Thomas
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to