0

I was actually doing this expression:

<class 'numpy.ndarray'>
np.array(w[0] + w[1]*np.array(X[:,0]) + w[2]*np.array(X[:,1]))

Now I have a Pandas dataframe and I wanna do it the same way but without converting it into a NumPy array, so what is the equivalent of this expression:

np.array(w[0] + w[1]*np.array(X[:,0]) + w[2]*np.array(X[:,1]))

in Pandas?

<class 'pandas.core.frame.DataFrame'>
Timus
  • 10,974
  • 5
  • 14
  • 28
Walid
  • 29
  • 3
  • Hi! Can you maybe show us a picture of the DataFrame you might be playing with? I think I have a rough idea of what you are asking but it is abit confusing and uncertain without context of what you're trying to achieve – Kim Hyun Bin Sep 18 '22 at 15:41
  • 2
    Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Sep 18 '22 at 15:43
  • What's `w` and `X`. I suspect all those `np.array(...)` wrappers aren't needed. – hpaulj Sep 18 '22 at 15:45
  • If `df` is your dataframe, why not: `w[0] + w[1] * df.iloc[:, 0] + w[2] * df.iloc[:, 1]`? – Timus Sep 18 '22 at 16:55

0 Answers0