Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!

Publication

Duplicate Column Names In Pandas: Updated
Latest   Machine Learning

Duplicate Column Names In Pandas: Updated

Last Updated on July 26, 2023 by Editorial Team

Author(s): Adam Ross Nelson

Originally published on Towards AI.

Pandas still permit duplicate column names, here is what you can do about it

This member-only story is on us. Upgrade to access all of Medium.

This article shows how easy it is to inadvertently generate a data frame in Pandas that has duplicate column names but without throwing an error. In an important update since an earlier article on the same topic, this article provides two ways to manage with or without duplicate column names.

Consider the following setup.

import pandas as pddata = {'first_name':['Adam','Tom','Sue','Pandi'], 'last_name':['Nelson','Jones','Pak','Sun'], 'topic_1':[1,2,1,1], 'topic_2':[2,2,2,1]}df = pd.DataFrame(data)

To produce the following data:

Image Credit: Data table generated by the author using the code in this article.

Then consider how you might decide to change the column… Read the full blog for free on Medium.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓