美文网首页
pandas map apply applymap

pandas map apply applymap

作者: hehehehe | 来源:发表于2020-09-11 13:34 被阅读0次

    Map: It iterates over each element of a series.
    df[‘column1’].map(lambda x: 10+x), this will add 10 to each element of column1.
    df[‘column2’].map(lambda x: ‘AV’+x), this will concatenate “AV“ at the beginning of each element of column2 (column format is string).

    Apply: As the name suggests, applies a function along any axis of the DataFrame.
    df[[‘column1’,’column2’]].apply(sum), it will returns the sum of all the values of column1 and column2.

    from shapely.geometry import Point
    data = [[116,115],[34,35]]
    df=pd.DataFrame(data)
    
    def gen(series):
        return Point([series[0],series[1]])
    
    df["g"] = df.apply(gen)
    gdf = gpd.GeoDataFrame(df,geometry='g')
    

    ApplyMap: This helps to apply a function to each element of dataframe.
    func = lambda x: x+2
    df.applymap(func), it will add 2 to each element of dataframe (all columns of dataframe must be numeric type)

    相关文章

      网友评论

          本文标题:pandas map apply applymap

          本文链接:https://www.haomeiwen.com/subject/hyovektx.html