Iloc并在熊猫中重命名

时间:2020-06-04 17:16:39

标签: python pandas rename

我是数据科学的新手,最近我一直在与熊猫一起工作,无法弄清楚以下几行在其中意味着什么!

df1=df1.rename(columns=df1.iloc[0,:]).iloc[1:,:]

问题指出,这是用来制作索引为11的列的标题,但我不知道如何? 我知道重命名的用法,但是无法理解多个iloc在这里发生了什么?

1 个答案:

答案 0 :(得分:1)

只需通过每种应用的方法来剖析线条:

InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run AssignVariableOp: Dst tensor is not initialized. [Op:AssignVariableOp]

实际上,它将删除第一行并设置为列名,这可以类似地完成:

df1 =                     # reassign df1 to ...
   df1.rename(            # the renamed frame of df1 ...
       columns =          # where column names will use mapper of ...
           df1.iloc[0,:]  # slice of df1 on row 0, include all columns ...
   )
   .iloc[1:,:]            # the slice of the renamed frame from row 1 forward, include all columns...