[Tutor] adding numpy to pandas

Peter Otten __peter__ at web.de
Thu Jun 21 13:23:51 EDT 2018


Mats Wichmann wrote:

> On 06/20/2018 02:04 PM, Glenn Schultz wrote:
>> All,
>> 
>> I have a pandas dataframe and a predict result (numpy array) of a
>> classifier [[0,1],[1,0]].  What I would like to do is as the positive to
>> the pandas dataframe.  I use predict[:,1] to slice the postive from
>> numpy which gives me a row of the result.  but I cannot concat to the
>> pandas df['result'] = predict[:,1] does not work and I have tried
>> various ways to do this with no result.  I am missing something here.
> 
> You should take a look here:
> 
> https://pandas.pydata.org/community.html
> 
> History has indicated that the Python tutor group isn't overloaded with
> Pandas experts. You may still get an answer here, but that page suggests
> the preferred places from the community to interact with to get good
> answers.  There's also a Google Groups which doesn't seem to be
> mentioned on the page:
> 
> https://groups.google.com/forum/#!forum/pydata

Regardless of the chosen forum, try to be as precise as possible with your 
problem description. It really can't get any worse than "does not work".

I tried but failed to reproduce your problem from what little information 
you provide:

>>> a = np.array([[0,1],[1,0]])
>>> df = pd.DataFrame([[1,2], [3,4]], columns=["a", "b"])
>>> df["result"] = a[:,1]
>>> df
   a  b  result
0  1  2       1
1  3  4       0

Please take the time to read http://sscce.org/ to learn how you can improve 
your question. You'll be rewarded with better answers from us or by the real 
experts elsewhere.

Thank you.




More information about the Tutor mailing list