@@ -29,6 +29,8 @@ df = pd.read_csv("https://github.com/pandas-dev/pandas/raw/main/doc/data/air_qua
29
29
- df.d_natsort_index
30
30
- df.d_natort_columns
31
31
- df.d_natsort_df_by_column
32
+ - d_rename_index
33
+ - d_rename_columns
32
34
33
35
** All methods added to pandas have one of this prefixes:**
34
36
@@ -79,7 +81,6 @@ Index(['country', 'city', 'date.utc', 'location', 'parameter', 'value',
79
81
5270 GB London 2019 - 04 - 09 03 :00 :00 + 00 :00 ... no2 67.0 µg/ m³
80
82
5271 GB London 2019 - 04 - 09 02 :00 :00 + 00 :00 ... no2 67.0 µg/ m³
81
83
[5272 rows x 7 columns]
82
-
83
84
```
84
85
85
86
### df.ds_sort_by_str_length
@@ -115,7 +116,6 @@ print(df2)
115
116
3548 Antwerpen BE 2019 - 05 - 19 21 :00 :00 + 00 :00 ... no2 12.5 µg/ m³
116
117
0 Antwerpen BE 2019 - 06 - 18 06 :00 :00 + 00 :00 ... pm25 18.0 µg/ m³
117
118
[5272 rows x 7 columns]
118
-
119
119
```
120
120
121
121
### d_insert_column_before_another
@@ -151,7 +151,6 @@ Out[7]:
151
151
5270 London GB 2019 - 04 - 09 03 :00 :00 + 00 :00 ... LondonGB 67.0 µg/ m³
152
152
5271 London GB 2019 - 04 - 09 02 :00 :00 + 00 :00 ... LondonGB 67.0 µg/ m³
153
153
[5272 rows x 8 columns]
154
-
155
154
```
156
155
157
156
### df.ds_reverse
@@ -384,7 +383,6 @@ Index(['pm25', 'pm25', 'pm25', 'pm25', 'pm25', 'pm25', 'pm25', 'pm25', 'pm25',
384
383
...
385
384
' no2' , ' no2' , ' no2' , ' no2' , ' no2' , ' no2' , ' no2' , ' no2' , ' no2' , ' no2' ],
386
385
dtype = ' object' , length = 5272 )
387
-
388
386
```
389
387
390
388
### df.d_natsort_index
@@ -486,3 +484,61 @@ Out[4]:
486
484
1825 Paris FR 2019 - 06 - 21 00 :00 :00 + 00 :00 ... no2 20.0 µg/ m³
487
485
[5272 rows x 7 columns]
488
486
```
487
+
488
+ ### df.d_rename_columns / df.d_rename_index
489
+
490
+ ``` python
491
+ df = pd.read_csv( " https://github.com/pandas-dev/pandas/raw/main/doc/data/titanic.csv" )
492
+
493
+ print (df)
494
+ PassengerId Survived Pclass ... Fare Cabin Embarked
495
+ 0 1 0 3 ... 7.2500 NaN S
496
+ 1 2 1 1 ... 71.2833 C85 C
497
+ 2 3 1 3 ... 7.9250 NaN S
498
+ 3 4 1 1 ... 53.1000 C123 S
499
+ 4 5 0 3 ... 8.0500 NaN S
500
+ .. ... ... ... ... ... ... ...
501
+ 886 887 0 2 ... 13.0000 NaN S
502
+ 887 888 1 1 ... 30.0000 B42 S
503
+ 888 889 0 3 ... 23.4500 NaN S
504
+ 889 890 1 1 ... 30.0000 C148 C
505
+ 890 891 0 3 ... 7.7500 NaN Q
506
+
507
+
508
+ df.d_rename_columns(Fare = ' Embarked' ,Embarked = ' Fare' ,Cabin = ' cabin2' )
509
+ df.d_rename_index({1 : 1000000 ,2 :50022 })
510
+ print (df)
511
+
512
+ PassengerId Survived Pclass ... Embarked cabin2 Fare
513
+ 0 1 0 3 ... 7.2500 NaN S
514
+ 1000000 2 1 1 ... 71.2833 C85 C
515
+ 50022 3 1 3 ... 7.9250 NaN S
516
+ 3 4 1 1 ... 53.1000 C123 S
517
+ 4 5 0 3 ... 8.0500 NaN S
518
+ ... ... ... ... ... ... ...
519
+ 886 887 0 2 ... 13.0000 NaN S
520
+ 887 888 1 1 ... 30.0000 B42 S
521
+ 888 889 0 3 ... 23.4500 NaN S
522
+ 889 890 1 1 ... 30.0000 C148 C
523
+ 890 891 0 3 ... 7.7500 NaN Q
524
+ [891 rows x 12 columns]
525
+
526
+ df.d_rename_columns({' Embarked' : ' Fare' , ' Fare' : ' Embarked' , ' cabin2' : ' Cabin' })
527
+ df.index = df.index.astype(' string' )
528
+ df.index = ' a' + df.index
529
+ df.d_rename_index(a1000000 = 1 ,a50022 = 2 )
530
+ print (df)
531
+
532
+ PassengerId Survived Pclass ... Fare Cabin Embarked
533
+ a0 1 0 3 ... 7.2500 NaN S
534
+ 1 2 1 1 ... 71.2833 C85 C
535
+ 2 3 1 3 ... 7.9250 NaN S
536
+ a3 4 1 1 ... 53.1000 C123 S
537
+ a4 5 0 3 ... 8.0500 NaN S
538
+ ... ... ... ... ... ... ...
539
+ a886 887 0 2 ... 13.0000 NaN S
540
+ a887 888 1 1 ... 30.0000 B42 S
541
+ a888 889 0 3 ... 23.4500 NaN S
542
+ a889 890 1 1 ... 30.0000 C148 C
543
+ a890 891 0 3 ... 7.7500 NaN Q
544
+ ```
0 commit comments