对python和pandas来说是新的。我确信我犯了很多python和编程罪行。此脚本在我的个人电脑上运行,但我的工作电脑运行它。但我的google fu很弱,无法找到解决方案让它工作,也无法找出iv以前工作时做错了什么。 我得到这个错误
Traceback (most recent call last):
File "A:\Python\doforms_data\Concept_script_working.pyw", line 1542, in <module>
main()
File "A:\Python\doforms_data\Concept_script_working.pyw", line 133, in main
machine_refactory.apply(lambda x : x.astype(str)+' '+x.name) #
File "C:\Users\agarth\AppData\Roaming\Python\Python38\site-packages\pandas\core\series.py", line 4045, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas/_libs/lib.pyx", line 2228, in pandas._libs.lib.map_infer
File "A:\Python\doforms_data\Concept_script_working.pyw", line 133, in <lambda>
machine_refactory.apply(lambda x : x.astype(str)+' '+x.name) #
AttributeError: 'str' object has no attribute 'astype'
这里是代码部分
machine_refactory_loc=df.columns.get_loc(1629)
machine_refactory=df.iloc[0:,(machine_refactory_loc):(machine_refactory_loc+2)]
machine_refactory=machine_refactory.astype(str)
machine_refactory.rename(columns = {1629:'Material'}, inplace = True) ## or Brick(1),Block(0)
machine_refactory.rename(columns = {1630:'Roof'}, inplace = True) ## Flat(1),Arched(0)
machine_refactory['Material'].replace('0','Block', inplace=True)
machine_refactory['Material'].replace('1','Brick', inplace=True)
machine_refactory['Roof'].replace('0',' - Arched Roof', inplace=True)
machine_refactory['Roof'].replace('1',' - Flat Roof', inplace=True)
machine_refactory=machine_refactory.astype(str)
machine_refactory['Refractory (Blocked or Bricked) Cremator']=machine_refactory['Material']+ machine_refactory['Roof']
machine_refactory=machine_refactory['Refractory (Blocked or Bricked) Cremator']
machine_refactory.apply(lambda x : x.astype(str)+' '+x.name) #
print(machine_refactory)
之后
machine_refactory
是一个系列,因此x
内的lambda
接受单元格值,这些值是字符串,因此x
没有astype
或name
属性。你想要:相关问题 更多 >
编程相关推荐