Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas Read txt with ID duplication on the end

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading