Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • 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

Sample 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
How to use apply() and unique() for sample data set using python
sample data set