slobokv83
slobokv83

Reputation: 173

How to read case-insensitive string of column name pandas

How can I read Excel documents which have the same number of columns and it should have same names of columns, but in some columns could be uppercase "d" and in others lowercase "d"?

I am appending data frames which I have to read first, but I have the problem when some columns have the name "Student_IDs" and others "Student_Ids"

for example:

df1

  A              Student_IDs
  some text      text
  text           some text

df2

  A              Student_Ids
  text1          some text1
  text2          some text2
  text3          some text3

this is the code (where dirname is the name of folder from which I am reading Excel documents):

for f in glob.glob(dirname + "/*.xlsx"):
    dfMerged = pd.read_excel(f)
    all_data = all_data.append(dfMerged,ignore_index=True)

and I have three columns instead of two.

EDIT: I need the names of columns to be "A" and "Student_IDs".

Upvotes: 0

Views: 2173

Answers (1)

lazy_frog
lazy_frog

Reputation: 165

You can solve this by doing dfMerged.columns = [x.lower() for x in dfMerged.columns] .

Upvotes: 1

Related Questions