Pandas Read txt with ID duplication on the end

Question:

I would like to ask for help with the following problem:

I need to use a downloaded txt data with this duplicate id at the end of the row structure.

UID  value1  value2
A01      99      10    A01
A02      29      12    A02
A03      96      14    A03

My desired output would look like

UID  value1  value2
A01      99      10
A02      29      12
A03      96      14

How can I use pandas to read this structure and drop the last duplicate column.

fun fact: Without special reading parameters, the UID column becomes index and every column shifts.

I have ideas to do workarounds, but I want to handle the problem in python and looking for a clean solution for this problem.

Thank you in advance!

Asked By: Botond Nagy

||

Answers:

For me working use index_col=False, then last column without header is removed:

df = pd.read_csv(file, index_col=False)

print (df)
   UID  value1  value2
0  A01      99      10
1  A02      29      12
2  A03      96      14
Answered By: jezrael
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.