how to take the linspace of values between 2 columns in pandas [on hold]
$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.
python functional-programming database pandas
New contributor
$endgroup$
put on hold as off-topic by Jamal♦ 18 mins 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.
add a comment |
$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.
python functional-programming database pandas
New contributor
$endgroup$
put on hold as off-topic by Jamal♦ 18 mins 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.
add a comment |
$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.
python functional-programming database pandas
New contributor
$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
python functional-programming database pandas
New contributor
New contributor
New contributor
asked 22 mins ago
Nicholas LeongNicholas Leong
1
1
New contributor
New contributor
put on hold as off-topic by Jamal♦ 18 mins 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♦ 18 mins 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.
add a comment |
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes