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

Is there a way to create a list of values out of existing column value in pandas?

Let’s say I have the following pandas dataframe:

sample_df

I would like to create a new column with the value of ColB and -1 * ColB. The resulting dataframe should look like this:

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

resulting_df

How can I achieve this efficiently?

>Solution :

simple way:

df['ColC'] = df['ColB'].astype(str) + ", " + (df['ColB']*-1).astype(str)
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