how to take the linspace of values between 2 columns in pandas [on hold]












0












$begingroup$


I am trying to take the linspace of between 2 columns of a dataset. Heres an example.



    a   b   C   D
0 3 13 3 13
1 4 14 4 14
2 5 15 5 15


I am trying to take the linspace between columns a and b a and turn it into a new column. Here is what I have so far:



def takinglinspace(): 
i = 0
for i in range(0,len(test.index)):
new=np.linspace(test['C'].iloc[i],test['D'].iloc[i],5)

test['E']= test['E'].apply(takinglinspace())


If i run the takinglinspace() function by itself it works. I get 3 lists of linspace values between the 2 columns. I cant seem to figure out how to insert that into the new column.



Applying the test['E'].apply I get the error



KeyError                                  Traceback (most recent call last)
C:Anaconda3libsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
3077 try:
-> 3078 return self._engine.get_loc(key)
3079 except KeyError:

pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()


Any reply is appreciated. Thanks.









share







New contributor




Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by Jamal 41 secs ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.





















    0












    $begingroup$


    I am trying to take the linspace of between 2 columns of a dataset. Heres an example.



        a   b   C   D
    0 3 13 3 13
    1 4 14 4 14
    2 5 15 5 15


    I am trying to take the linspace between columns a and b a and turn it into a new column. Here is what I have so far:



    def takinglinspace(): 
    i = 0
    for i in range(0,len(test.index)):
    new=np.linspace(test['C'].iloc[i],test['D'].iloc[i],5)

    test['E']= test['E'].apply(takinglinspace())


    If i run the takinglinspace() function by itself it works. I get 3 lists of linspace values between the 2 columns. I cant seem to figure out how to insert that into the new column.



    Applying the test['E'].apply I get the error



    KeyError                                  Traceback (most recent call last)
    C:Anaconda3libsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
    3077 try:
    -> 3078 return self._engine.get_loc(key)
    3079 except KeyError:

    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()


    Any reply is appreciated. Thanks.









    share







    New contributor




    Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$



    put on hold as off-topic by Jamal 41 secs ago


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

    If this question can be reworded to fit the rules in the help center, please edit the question.



















      0












      0








      0





      $begingroup$


      I am trying to take the linspace of between 2 columns of a dataset. Heres an example.



          a   b   C   D
      0 3 13 3 13
      1 4 14 4 14
      2 5 15 5 15


      I am trying to take the linspace between columns a and b a and turn it into a new column. Here is what I have so far:



      def takinglinspace(): 
      i = 0
      for i in range(0,len(test.index)):
      new=np.linspace(test['C'].iloc[i],test['D'].iloc[i],5)

      test['E']= test['E'].apply(takinglinspace())


      If i run the takinglinspace() function by itself it works. I get 3 lists of linspace values between the 2 columns. I cant seem to figure out how to insert that into the new column.



      Applying the test['E'].apply I get the error



      KeyError                                  Traceback (most recent call last)
      C:Anaconda3libsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
      3077 try:
      -> 3078 return self._engine.get_loc(key)
      3079 except KeyError:

      pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
      pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
      pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
      pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()


      Any reply is appreciated. Thanks.









      share







      New contributor




      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am trying to take the linspace of between 2 columns of a dataset. Heres an example.



          a   b   C   D
      0 3 13 3 13
      1 4 14 4 14
      2 5 15 5 15


      I am trying to take the linspace between columns a and b a and turn it into a new column. Here is what I have so far:



      def takinglinspace(): 
      i = 0
      for i in range(0,len(test.index)):
      new=np.linspace(test['C'].iloc[i],test['D'].iloc[i],5)

      test['E']= test['E'].apply(takinglinspace())


      If i run the takinglinspace() function by itself it works. I get 3 lists of linspace values between the 2 columns. I cant seem to figure out how to insert that into the new column.



      Applying the test['E'].apply I get the error



      KeyError                                  Traceback (most recent call last)
      C:Anaconda3libsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
      3077 try:
      -> 3078 return self._engine.get_loc(key)
      3079 except KeyError:

      pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
      pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()
      pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
      pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()


      Any reply is appreciated. Thanks.







      python functional-programming database pandas





      share







      New contributor




      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 mins ago









      Nicholas LeongNicholas Leong

      1




      1




      New contributor




      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Nicholas Leong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by Jamal 41 secs ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.







      put on hold as off-topic by Jamal 41 secs ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.






















          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар