python如何处理pandas_pythonpandas如何处理表列表?

最简单的方法是完全分解这些代码:# List of 3 dataframes

table_list = [tablea, tableb, tablec]

# function that cleans 1 dataframe

# This will get applied to each dataframe in table_list

# when the python function map is used AFTER this function

def clean_data(df):

# for loop.

# df[i] will be a different column in df for each iteration

# i iterates througn column names.

for i in df:

# df[i] = will overwrite column i

# df[i].map(lambda x: round(x, 4)) in this case

# does the same thing as df[i].apply(lambda x: round(x, 4))

# in other words, it rounds each element of the column

# and assigns the reformatted column back to the column

df[i] = df[i].map(lambda x: round(x, 4))

# returns the formatted SINGLE dataframe

return df

# I expect this is where the confusion comes from

# this is a python (not pandas) function that applies the

# function clean_df to each item in table_list

# and returns a list of the results.

# map was also used in the clean_df function above. That map was

# a pandas map and not the same function as this map. There do similar

# things, but not exactly.

map(clean_data, table_list)

希望有帮助。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值