I. Modify the order of the table data type DataFrame columns
Real-world scenarios:Pandas How to Modify the Order of Table Data Types DataFrame Columns
1.1 Key knowledge points
- File reading and writing
- basic grammar
- Data construction
- Pandas
- Numpy
Real War:
1.2 Creating python files
import numpy as np import pandas as pd (66) df = ((10, 4), columns=list('ABCD')) print(df) df = df[["D", "A", "B", "C"]] print(df)
1.3 Operational results
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
3 0.298641 0.031346 0.678006 0.903489
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
8 0.049213 0.465223 0.941233 0.216512
9 0.361318 0.031319 0.304045 0.188268
D A B C
0 0.679109 0.154288 0.133700 0.362685
1 0.557619 0.194450 0.251210 0.758416
2 0.829095 0.514803 0.467800 0.087176
3 0.903489 0.298641 0.031346 0.678006
4 0.634057 0.514451 0.539105 0.664328
5 0.879319 0.353419 0.026643 0.165290
6 0.096294 0.067820 0.369086 0.115501
7 0.771043 0.083770 0.086927 0.022256
8 0.216512 0.049213 0.465223 0.941233
9 0.188268 0.361318 0.031319 0.304045
Second, Pandas how to count the number of null values in a data column
Practical scenarios: Pandas how to count the number of null values in a data column
2.1 Key knowledge points
- File reading and writing
- basic grammar
- Pandas
- numpy
Real War:
2.2 Creating python files
""" as followsDF,Setting the value of two cells ·utilizationiloc set up(3,B)The value ofnan ·utilizationlocset up(8,D)The value ofnan """ import numpy as np import pandas as pd (66) df = ((10, 4), columns=list('ABCD')) [3, 1] = [8, 'D'] = print(df) print(().sum())
2.3 Operational results
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
3 0.298641 NaN 0.678006 0.903489
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
8 0.049213 0.465223 0.941233 NaN
9 0.361318 0.031319 0.304045 0.188268
A 0
B 1
C 0
D 1
dtype: int64
Three,How Pandas Removes Rows Containing Null Values
Real-world scenarios:How Pandas Removes Rows Containing Null Values
3.1 Key knowledge points
- File reading and writing
- basic grammar
- Pandas
- numpy
Real War:
3.2 Creating python files
""" as followsDF,Setting the value of two cells ·utilizationiloc set up(3,B)The value ofnan ·utilizationlocset up(8,D)The value ofnan """ import numpy as np import pandas as pd (66) df = ((10, 4), columns=list('ABCD')) [3, 1] = [8, 'D'] = print(df) df2 = () print(df2)
3.3 Operational results
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
3 0.298641 NaN 0.678006 0.903489
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
8 0.049213 0.465223 0.941233 NaN
9 0.361318 0.031319 0.304045 0.188268
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
9 0.361318 0.031319 0.304045 0.188268
Fourth, Pandas how to accurately set the value of the form data cells
Real-world scenarios:How Pandas precisely sets the value of a cell of tabular data
4.1 Key knowledge points
- File reading and writing
- basic grammar
- Pandas
- numpy
Real War:
4.2 Creating python files
""" as followsDF,Setting the value of two cells ·utilizationiloc set up(3,B)The value ofnan ·utilizationlocset up(8,D)The value ofnan """ import numpy as np import pandas as pd (66) df = ((10, 4), columns=list('ABCD')) print(df) [3, 1] = [8, 'D'] = print(df)
4.3 Operational results
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
3 0.298641 0.031346 0.678006 0.903489
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
8 0.049213 0.465223 0.941233 0.216512
9 0.361318 0.031319 0.304045 0.188268
A B C D
0 0.154288 0.133700 0.362685 0.679109
1 0.194450 0.251210 0.758416 0.557619
2 0.514803 0.467800 0.087176 0.829095
3 0.298641 NaN 0.678006 0.903489
4 0.514451 0.539105 0.664328 0.634057
5 0.353419 0.026643 0.165290 0.879319
6 0.067820 0.369086 0.115501 0.096294
7 0.083770 0.086927 0.022256 0.771043
8 0.049213 0.465223 0.941233 NaN
9 0.361318 0.031319 0.304045 0.188268
To this article on Python Pandas modify the table data type DataFrame columns of the order of the case is introduced to this article, more related Python Pandas content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!