Apply Function
By defining a function beforehand
The apply( ) function is used to iterate over a data frame. It can also be used with lambda functions.
Python3
# Apply function def fun(value): if value > 70 : return "Yes" else : return "No" data_frame[ 'Customer Satisfaction' ] = data_frame[ 'Spending Score (1-100)' ]. apply (fun) data_frame.head( 10 ) |
Output:
CustomerID Genre Age Annual Income (k$) Spending Score (1-100) \
0 1 Male 19 15 39
1 2 Male 21 15 81
2 3 Female 20 16 6
3 4 Female 23 16 77
4 5 Female 31 17 40
5 6 Female 22 17 76
6 7 Female 35 18 6
7 8 Female 23 18 94
8 9 Male 64 19 3
9 10 Female 30 19 72
NewColumn Customer Satisfaction
0 1 No
1 1 Yes
2 1 No
3 1 Yes
4 1 No
5 1 Yes
6 1 No
7 1 Yes
8 1 No
9 1 Yes
Data Processing with Pandas
Data Processing is an important part of any task that includes data-driven work. It helps us to provide meaningful insights from the data. As we know Python is a widely used programming language, and there are various libraries and tools available for data processing.
In this article, we are going to see Data Processing in Python, Loading, Printing rows and Columns, Data frame summary, Missing data values Sorting and Merging Data Frames, Applying Functions, and Visualizing Dataframes.
Table of Content
- What is Data Processing in Python?
- What is Pandas?
- Loading Data in Pandas DataFrame
- Printing rows of the Data
- Printing the column names of the DataFrame
- Summary of Data Frame
- Descriptive Statistical Measures of a DataFrame
- Missing Data Handing
- Sorting DataFrame values
- Merge Data Frames
- Apply Function
- By using the lambda operator
- Visualizing DataFrame
- Conclusion
Contact Us