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

Drop column from tuple list in Pandas dataframe

This is my tuple I guess

df = [(1.8799187420058687, 1), (1.5963945918878317, 2)]

The type of df shows up as this

print(type(df))
<type 'list'>

My goal is to remove the second variable column displayed as 1 and 2

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

This is how I came up to the result (if that can help)

df = df.groupby('CBF_01').mean()
df = list(zip(df,df.index))

Expected output

df = (1.8799187420058687,1.5963945918878317)

>Solution :

loop through each tuple, save the first value in a list and convert it to tuple.

new_df = tuple([x[0] for x in df])

output: (1.8799187420058687, 1.5963945918878317)
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