Pandas in DateFrame Change column names

When doing data mining , I want to change it DataFrame Of column name , So I checked , Summarized below :
The data are as follows :

>>>import pandas as pd
>>>a = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6], 'C':[7,8,9]})
>>> a
A B C
0 1 4 7
1 2 5 8
2 3 6 9

Method 1 : Violence method

>>>a.columns = ['a','b','c']
>>>a
a b c
0 1 4 7
1 2 5 8
2 3 6 9

But the disadvantage is that you have to write three , Or report a mistake .

Method 2 : Better way

>>>a.rename(columns={'A':'a', 'B':'b', 'C':'c'}, inplace = True)
>>>a
a b c
0 1 4 7
1 2 5 8
2 3 6 9

The advantage is that you can change the number at will :

>>>a.rename(columns={'A':'a', 'C':'c'}, inplace = True)
>>>a
a B c
0 1 4 7
1 2 5 8
2 3 6 9

You can just change ’A’,’C’, Don't change ’B’.

Pandas in DateFrame More articles about modifying column names

  1. Pandas in DataFrame Change column names

    Pandas in DataFrame Change column names : Use rename df = pd.read_csv('I:/Papers/consumer/codeandpaper/TmallData/result01- ...

  2. 【 Reprint 】C# in Datatable Change column names

    stay C# Data table of DataTable In operation , Sometimes there are changes DataTable Requirements for column names of data tables , Actually C# Medium DataTable The column name of supports manual modification and adjustment , Can pass DataTable Class Columns ...

  3. Spark And Pandas in DataFrame contrast

      Pandas Spark Operation mode stand-alone single machine tool, There is no parallel mechanism parallelism I won't support it Hadoop, There are bottlenecks in processing large amounts of data Distributed parallel computing framework , Built in parallel mechanism paral ...

  4. Spark And Pandas in DataFrame contrast ( detailed )

      Pandas Spark Operation mode stand-alone single machine tool, There is no parallel mechanism parallelism I won't support it Hadoop, There are bottlenecks in processing large amounts of data Distributed parallel computing framework , Built in parallel mechanism paral ...

  5. pandas in loc-iloc-ix Use

    from :https://www.jianshu.com/p/d6a9845a0a34 Pandas in loc,iloc,ix Use Use iloc from DataFrame Filter data in iloc Is based on “ Location ” ...

  6. mysql Modify column name and column type

    MySQL Modify the column name or data type in (2012-04-03 08:59:25) Reprint ▼ label : mysql Change column names Modify column data type it classification :  database Refer to the syntax in the link below http://dev. ...

  7. stay sql There is no way to modify the table structure in the design

    When doing exercises, the watch is often not well designed , Later, I have to go to the database to modify the table structure, but I have no words. When I modify the interface, I will prompt to save from http://www.57xue.com/ItemView/Sql/2016061600160.ht ...

  8. pandas The grouping technology in

    Catalog 1   Grouping operation 1.1   Group by column 1.2   Group by Dictionary 1.3   Grouping by function 1.4   according to list Combine 1.5   Group by index level 2   Grouping operations 2.1  agg 2 ...

  9. DataFrame Change column names

    hold Dataframe Format column name 'class1' It is amended as follows 'class_label' data.rename(columns={"label":"true_label" ...

Random recommendation

  1. application ERP The relationship between system and enterprise

       With ERP The further development of the system , More and more enterprises begin to implement ERP,ERP Implementation is to use a new management mode to transform the old management mode of the original enterprise , It is advanced. . Effective management ideas and methods .ERP In the practical application of the software , The depth and breadth of its application ...

  2. 【BZOJ-1833】count Number counting digit DP

    1833: [ZJOI2010]count Number counting Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 2494  Solved: 1101[Submit][ ...

  3. paip. The best scripting language node js Environment building connection mysql

    paip. The best scripting language node js  Environment building connection mysql #==== download node... Go eleven exe.. Easy .. 1 #0----Hello world   .js 2 #--------- model ...

  4. iOS In development EXC_BAD_ACCESS Another reason for that

    I'm learning by chance today iOS When I was developing, I came across a EXC_BAD_ACCESS It's abnormal , After checking the data, the explanation is due to the access to the heap memory object that has been recycled , Reference resources : http://code.tutsplus.com/tutor ...

  5. OC grammar 10——@protocol agreement ,

    Reference material : Blog @protocol, agreement : OC in protocol And Java The meaning of interface in is the same , Their purpose is to define a set of method specifications . Methods in the classes that implement this protocol , Must follow the method specification defined in this protocol . ...

  6. About " Module computer type conflicts with target computer type " The solution of the

    Problem description : my 64 This project includes 32 Error after bit static library ( Module computer type "x86" With the target computer type "x64" Conflict ), Change the project to 32 Bit after , An error again ( A number of unresolved external ...

  7. 201621123023《Java Programming 》 The first 13 Weekly learning summary

    One . This week's learning summary In the way you like ( Mind mapping .OneNote Or others ) Summarize the related content of multiple networks . Two . Add network capabilities to your system ( The shopping cart . Library management . Fight the landlord and so on )- In groups In order that your system can be shared by multiple users through the network ...

  8. js Get the monitor 、 Page equal height ( turn )

    Page visible area width :document.body.clientWidth Page visible area high :document.body.clientHeight Page visible area width :document.body.offsetWidth ...

  9. 【 turn 】tcp_tw_recycle and tcp_timestamps Lead to connect The problem of failure

    (2012-02-01 18:40:32)     Recently, some of them have appeared online connect Failure problem , After analysis and test , Final confirmation and proc Parameters tcp_tw_recycle/tcp_timestamps relevant : ...

  10. 【codevs2822】 Love is in the heart

    Title Description  Description “ Everyone has a dream , Even if they're different , To be able to share with you , No matter what failure, success will be moved . Love is in the heart , Ordinary but not mediocre , The world is like a maze , But let us meet at this moment Our Home.” In the land of love ...