Issue
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".
Solution
You can solve this by doing
dfMerged.columns = [x.lower() for x in dfMerged.columns]
.
Answered By - lazy_frog
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.