我有以下资料:
df
Site In Site Out Transmission Commodity parameter value unit
0 Mid North hvac Elec eff 9.000000e-01
1 Mid North hvac Elec inv-cost 1.650000e+06
2 Mid North hvac Elec fix-cost 0.000000e+00
3 Mid North hvac Elec var-cost 0.000000e+00
4 Mid North hvac Elec inst-cap 0.000000e+00
5 Mid North hvac Elec cap-lo 0.000000e+00
6 Mid North hvac Elec cap-up 1.500000e+15
7 Mid North hvac Elec wacc 7.000000e-02
8 Mid North hvac Elec depreciation 4.000000e+01
9 Mid South hvac Elec eff 9.000000e-01
...
当我这样做的时候,它就起作用了:
len(df.Transmission)
54
我如何获得'Site In'
或'Site Out'
的len(),因为它们的名称中有空格,所以我找不到使用.column_name
的方法???
老实说,有几种方法可以获得长度,但是在这种情况下有没有方法使用.column_name
?你知道吗
以下操作无效:
len(df.Site In)
*** SyntaxError: invalid syntax
len(df.SiteIn)
*** AttributeError: 'DataFrame' object has no attribute 'SiteIn'
len(df.Site_In)
*** AttributeError: 'DataFrame' object has no attribute 'Site_In'
len(df.Site' 'In)
*** SyntaxError: invalid syntax
len(df['Site In'])
和len(df['Site Out'])
df['Site Out'].column.values
和df['Site In'].column.values
来重命名这些列,这样您的方法就可以工作了。你知道吗也有很多方法,但这些是最常见的。你知道吗
相关问题 更多 >
编程相关推荐