python-如何将多个数据帧的列表传递给我定义的函数?
发布时间:2022-07-21 09:51:16 281
相关标签: # node.js
我试图在Python中创建一个函数,允许我将包含多个数据帧的列表传递给它,然后它将对列表对象中的所有数据帧执行相同的清理方法。
import pandas as pd
my_dfs = []
xl_wb_filepath_df1 = input("Enter the path to your file: ")
xl_wb_filepath_df2 = input("Enter the path to your file: ")
df1 = pd.read_excel(xl_wb_filepath_df1, sheet_name= 'Summary')
df2 = pd.read_excel(xl_wb_filepath_df2, sheet_name= 'Summary')
my_dfs.append([df1, df2])
def data_cleaning(df):
df.replace(regex=r'_95C_XXXX', value='_85C_YYYY', inplace= True)
df.dropna(axis= 1, how= "all", inplace= True)
df.rename(columns=df.iloc[0], inplace= True)
df.drop(df.index[0], inplace= True)
df.drop(columns= ['NAME_OTHERNAME_85C_YYYY', 'END'], inplace= True)
df.dropna(axis = 0, how= "all", inplace= True)
df.set_index("USECASE_LIST_85C_YYYY", inplace= True)
df.index.names = ["SYS_MODS_85C_YYYY"]
data_cleaning(my_dfs)
这是我得到的 Python 异常: AttributeError: 'list' object has no attribute 'replace'
任何建议将不胜感激!谢谢你。
也许 for 循环会起作用,但我也遇到了问题。
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报