【Pandas】[6] DataFrame batch modify column name

Requirements: After reading data from hive using pandas. Each column will be added with the hive table name. example: hive_table_name.column_name. Therefore, you need to remove the "hive_table_name." in the column name at this time

 

Two ways:

Way 1:

df.columns = [i.split('.', 1)[1] for i in df.columns]

Way 2:

df.columns = df.columns.map(lambda x: x.split('.', 1)[1])

Now complete

Guess you like

Origin blog.csdn.net/xiezhen_zheng/article/details/105364615