Python Forum
Pandas: Accessing column headers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas: Accessing column headers
#1
Hello,

I have a problem I am trying to solve in Python using Pandas. I have a dictionary of dictionaries that I will eventually be transforming into an sql database. Each of the dictionaries in the dictionary is an excel spreadsheet. Before I can create the database, I must clean up the data. This involves editing the column headers in each dictionary. I need to iterate through every single column header in every single dictionary. If the first character of each column header is non-alpha, i must prepend the column name with "c_". I have iterated through the dictionaries to replace other characters such as ' ' and '%' but I am not sure how to access the first character of each column header and test whether .isalpha() is true or not. If anyone could help, it would be greatly appreciated. Thanks!

P.S.-

so far what I have been doing is this-

for file in files:
   dict_[file].rename(columns = lambda x: x.replace('/', '_'), inplace = True)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  creating dict out of CSV file without the headers ranbarr 6 2,616 May-09-2021, 08:26 PM
Last Post: ranbarr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020