#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to use apply() and unique() for sample data set using python?
Description

To use apply(),unique() function for a given data sample in python.

Process

  Import pandas library.

  Load the sample data.

  Create the date frame.

  Use apply() and unique() functions

Sapmle Code

#Import library functions

import pandas as pd

import numpy as np

#sample data set

data={'salary'
:[100,200,300,400,500,400,
300,200,100,50], 'age':[25,
26,25,23,30,29,23,23,25,25],

'rating':[4,3.24,2.5,2.25,2,2.25,
2.5,2.75,3.2,4.2], 'bonus':[2500,1200,
900,3000,1800,1400,850,250,750, 1000]}

#create data frame

df=pd.DataFrame(data)

#call unique()

u=df['salary'].unique()

print("The result of unique() is\n",u)

#call apply()

a=df.apply(np.log)

print("The result of apply() is\n",a)

Screenshots