Length mismatch error when assigning new column labels in pandas dataframe

前端 未结 1 1886
刺人心
刺人心 2021-01-12 18:49

The tab file I\'m working with is missing the final column name. When I attempt to repair the header by appending the missing value, I get a mismatch error. Here\'s an exa

相关标签:
1条回答
  • 2021-01-12 19:36

    The problem was the argument index_col=0 was beginning column indexing at the gene names:

    The above dataframe ended at 2073, which with 1-based indexing with the above argument, was 2073 elements: one element fewer than my repaired header. This generated the following error:

    ValueError: Length mismatch: Expected axis has 2073 elements, new values have 2074 elements

    While the same read_csv command with index_col=None assigned a separate numerical index, putting the (in this case gene names) back into the dataframe from being just labels:

    The above dataframe ended at the column number 2073, which is 2074 elements with zero-based indexing: the same length as my repaired header! Problem solved:

    0 讨论(0)
提交回复
热议问题