Learn Python
Learn Data Structure & Algorithm
Learn Numpy
Pandas Introduction
Pandas Series
Pandas DataFrame
Pandas Read Files
Pandas Some functions and properties
Pandas Math Function
Pandas Selection
Pandas Change Type
Pandas Concatenate & Split
Pandas Sorting
Pandas Filter
Pandas Data Cleaning
Pandas Group by
Pandas Time Series
Pandas Analysis 1
Pandas Analysis 2
Pandas Analysis 3
Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
Id | Name | Group_name | Total_marks | Grade | Ranking | |
---|---|---|---|---|---|---|
0 | 01 | A | Science | 700 | A+ | 01 |
1 | 02 | B | Commerce | 618 | B+ | 02 |
2 | 03 | A | Science | 700 | A+ | 01 |
3 | 04 | D | Arts | 687 | A+ | 01 |
4 | 05 | E | Commerce | 611 | B+ | 02 |
5 | 06 | F | Arts | 599 | C+ | 03 |
6 | 07 | P | Science | 575 | C+ | 03 |
7 | 08 | F | Arts | 600 | C | 03 |
8 | 09 | I | Commerce | 550 | C+ | 03 |
9 | 10 | J | Science | 650 | A+ | 01 |
10 | 11 | K | Arts | 680 | A+ | 01 |
11 | 12 | L | Science | 570 | C+ | 03 |
12 | 13 | M | Arts | 599 | C+ | 03 |
13 | 14 | N | Commerce | 597 | C+ | 03 |
14 | 15 | O | Science | 697 | A+ | 01 |
15 | 16 | B | Arts | 570 | C+ | 03 |
16 | 17 | D | Science | 588 | C+ | 03 |
17 | 18 | E | Science | 687 | A+ | 01 |
18 | 19 | C | Commerce | 688 | A+ | 01 |
19 | 20 | P | Arts | 588 | C+ | 03 |
20 | 21 | C | Science | 619 | B+ | 02 |
21 | 22 | M | Commerce | 600 | B+ | 02 |
22 | 23 | P | Arts | 700 | A+ | 01 |
Astype function is used to data type conversion like float to int or string, string to float or int and int to float or string.
To convert float to integer, round those float values before converting into integer.
Id | Money | |
---|---|---|
0 | 1.12 | $4,334.00 |
1 | 2.31 | $4,343.00 |
2 | 3.00 | $4,352.00 |
3 | 4.11 | $4,361.00 |
4 | 5.01 | $4,370.00 |
5 | 6.21 | $4,379.00 |
If you have string in numeric column then you can't convert that column into integer or float using astype. So you have to use to_numeric function and use an extra parameter and that is errors="coerce". When this parameter gets a string it will make that cell nan. After doing this you will get a numeric column and to change it into float or int you can use astype function.
Suppose you have some symbol(dollar, comma, etc) with numeric values. You can't convert those values into numeric from with those symbols. For the conversion, you have to remove those symbols. After removing the symbol you can change those values into float or integer.
Id | Money | |
---|---|---|
0 | 01 | $4,334.00 |
1 | 02 | $4,343.00 |
2 | 03 | $4,352.00 |
3 | 04 | $4,361.00 |
4 | 05 | $4,370.00 |
5 | 06 | $4,379.00 |
Name: money, dtype: object
Id | Money | |
---|---|---|
0 | 01 | 4334.0 |
1 | 02 | 4343.0 |
2 | 03 | 4352.0 |
3 | 04 | 4361.0 |
4 | 05 | 4370.0 |
5 | 06 | 4379.0 |