回覆列表
  • 1 # 使用者5768971435873

    pandas.DataFrame.iterrowsDataFrame.iterrows()迭代(iterate)覆蓋整個DataFrame的行中,返回(index,Series)對。importnumpyasnpimportpandasaspddef_map(data,exp):forindex,rowindata.iterrows():#獲取每行的index、rowforcol_nameindata.columns:row[col_name]=exp(row[col_name])#把結果返回給datareturndatadef_1map(data,exp):_data=[[exp(row[col_name])#把結果轉換成2級listforcol_nameindata.columns]forindex,rowindata.iterrows()]return_dataif__name__=="__main__":inp=[{"c1":10,"c2":100},{"c1":11,"c2":110},{"c1":12,"c2":120}]df=pd.DataFrame(inp)temp=_map(df,lambdaele:ele+1)printtemp_temp=_1map(df,lambdaele:ele+1)res_data=pd.DataFrame(_temp)#對2級list轉換成DataFrameprintres_data

  • 中秋節和大豐收的關聯?
  • 二手1.4T高爾夫和全新1.2T要哪個?