你知道吗df.sort\u值在《熊猫不为我工作》一书中,同样的df在没有被分类的情况下被返回。你知道吗
def findExpression(transType, sortColName=None):
global df
if transType == 'sortAscending':
df.sort_values(sortColName)
return df
print(findExpression('sortAscending', sortColName='col9'))
Actual Output:
col1 col2 col3 col4 col5 col6 col7 col8 col9
0 12345 12ab 2008-11-22 2009-11-22 beans 25.0 715.0 True 10
1 67890 34cd 2009-12-23 2010-12-23 catzilla 25.0 75.0 False 6
2 13579 56ef 2010-01-24 2011-01-24 boots 25.0 75.0 True 5
3 24680 78gh 2011-02-25 2012-02-25 whitish 25.0 75.0 True 6
4 12560 90ij 2012-03-26 2013-03-26 coco 25.0 75.0 True 1
Expected:
col1 col2 col3 col4 col5 col6 col7 col8 col9
0 12560 90ij 2012-03-26 2013-03-26 coco 25.0 75.0 True 1
1 13579 56ef 2010-01-24 2011-01-24 boots 25.0 75.0 True 5
2 24680 78gh 2011-02-25 2012-02-25 whitish 25.0 75.0 True 6
3 67890 34cd 2009-12-23 2010-12-23 catzilla 25.0 75.0 False 6
4 12345 12ab 2008-11-22 2009-11-22 beans 25.0 715.0 True 10
大多数pandas函数不直接修改元素,而是返回元素的修改副本。如果要直接修改对象,必须添加选项
inplace = True
:这与执行以下操作相同:
相关问题 更多 >
编程相关推荐