【问题标题】:How to solve the problem: can't assign to literal (Python)?如何解决问题:不能分配给文字(Python)?
【发布时间】:2023-03-14 21:01:01
【问题描述】:

对于以下代码,我收到错误:无法分配给文字

for i in range(len(stepData)):
    stepDataLeft = stepData.to_numpy()[i, 0:5]
    stepDataRight = stepData.to_numpy()[i, 5:10]
    dataF = pd.DataFrame({'stepDataLeft': stepDataLeft, 'stepDataRight': stepDataRight}, index=['Stride Length Mean', 'Stand Duration Mean', 'Swing Duration Mean', 'Douple Support Time Mean', 'Relation Swing Stand Mean'])
    dataF = ['Symmetry Ratio Row']=resultsPerRowRatio.append(np.where(dataF['stepDataLeft'] < dataF['stepDataRight'],sv.symmetryRatio(dataF['stepDataLeft'],dataF['stepDataRight']), sv.symmetryRatio(df['stepDataRight'],df['stepDataLeft'])))
print(str(dataF))

-

import numpy as np

def symmetryRatio(L, R):
    result = L/R
    return result

谁能解释一下问题出在哪里以及如何解决?

编辑 1

编辑 2

在我更正后,我得到了这个错误:

【问题讨论】:

  • 请在 breif 中指定错误或将其与您的问题一起粘贴
  • 哦,是的。你是对的。谢谢你。但后来我收到了这个错误:KeyError: 'stepDataRight' 我不知道这意味着什么以及如何解决这个问题。

标签: python list numpy-ndarray


【解决方案1】:

改为这样写:

dataF['Symmetry Ratio Row'] = ...

【讨论】:

  • 哦,是的。你是对的。但后来我得到这个错误: KeyError: 'stepDataRight'
  • @hugmath 这意味着您的数据框没有这样的列。也许您打算在前两行创建列,或者您打算在最后一行使用变量名?
  • 我想要三个列名:StepDataLeft、StepDataRight 和 SymmetryRatioRow
  • @hugmath 那么第一行应该是dataF['stepDataLeft']=...
猜你喜欢
  • 1970-01-01
  • 2023-02-10
  • 2011-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-22
相关资源
最近更新 更多