我有一个简单的clean_data函数,它将对输入数据帧中的数字进行四舍五入。代码可以工作,但我很困惑它为什么能工作。有人能帮我理解吗?在
我感到困惑的地方是这个。table_list是一个新的数据帧列表,因此在运行代码之后,table_list中的每一项都应该被格式化,而tablea、tableb和tablec应该保持不变。但显然我错了。运行代码后,所有三个表的格式都正确。怎么回事?非常感谢你的帮助。在
table_list = [tablea, tableb, tablec]
def clean_data(df):
for i in df:
df[i] = df[i].map(lambda x: round(x, 4))
return df
map(clean_data, table_list)
最简单的方法是完全分解这些代码:
希望有帮助。在
在Python中,数据帧或任何复杂对象的列表只是指向底层数据帧的引用列表。例如,table_list的第一个元素是对tablea的引用。因此,clean_数据将直接进入数据帧,即tablea,遵循table_list[0]给出的参考。在
相关问题 更多 >
编程相关推荐