![]() ![]() Just like most things in pandas, there are several ways to rename columns. Index(['Symbol', 'Security', 'GICS Sector', 'Headquarters Location',Īnd I think some of the names are not intuitive for me, so I’m going to rename the following: We are left with the following columns: > df.columns Dublin, Ireland 1989Īfter dropping the columns, we can check the df.head() to confirm the drop was successful – now there are only 5 columns. Danvers, Massachusetts 1981Ĥ ACN Accenture plc. ![]() North Chicago, Illinois 2013 (1888)ģ ABMD ABIOMED Inc. North Chicago, Illinois 1888Ģ ABBV AbbVie Inc. Paul, Minnesota 1902ġ ABT Abbott Laboratories. Headquarters Location FoundedĠ MMM 3M Company. We don’t need the following columns so let’s drop them: SEC filings, GICS Sub Industry, Date first added, and CIK. First, we are going to remove some unwanted columns. Let’s make some modifications to the dataframe. 'Headquarters Location', 'Date first added', 'CIK', 'Founded'],ĭtype='object') Wikipedia SP 500 company list Index(['Symbol', 'Security', 'SEC filings', 'GICS Sector', 'GICS Sub Industry', A screenshot of the actual Wikipedia page is also included below for reference. Some of them are hidden as represented by the “…” in the above display. The pandas library provides a convenient way to read data from a web page, so we’ll load up a table from Wikipedia – the S&P 500 companies list. This tutorial is part of the “Integrate Python with Excel” series, you can find the table of content here for easier navigation. This tutorial will walk through how to change names in a dataframe. For example, maybe you want the column names to be more descriptive, or maybe you want to shorten the names. There are many reasons to rename pandas dataframe columns.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |