I've read excel file using pd.read_excel
and i also have specified from which sheets i want them using Regex.
def gettingSheetName(_directory,_regex):
'''reads the file using regex as a pattern for Sheet name'''
xl = pd.ExcelFile(_directory)
regex = re.compile(_regex)
sheets = [n for n in xl.sheet_names if regex.match(n)]
if sheets:
return pd.read_excel(xl, sheet_name=sheets,index_col=False)
Therefor in return i get a Dictionary with 3 Dimensions.
{'SheetName': Col1 Col2
0 27 someText
1 35 someText
.. ... ...
171 4444 someText
172 6666 someText
i've tried pd.DataFrame.from_dict(Dic)
to convert this to Pandas Data frame. and i got this error
If using all scalar values, you must pass an index
i also tried this code that i found pd.DataFrame(list(Sach.items()), columns=['Col1', 'Col2'])
but the resualt looks like this
Col1 col2
0 Sheetname Col1 Col2 0....
Sheet name goes to value and after that Columns and finally the values that i'm assuming are starting with the first index which was 0 I've search everywhere and all i could find was for 2D Dic which doesn't consider the Sheet name. although i used this for loop instead of other popular methods which does the job, my Question is is there any way that i can use a Pandas function to achieve this? or possibly can i Not take the Sheetname from the beginning?
for key in Dic:
Dic=Dic[key]
EDIT 1:
so after using return pd.concat(pd.read_excel(xl, sheet_name=sheets,index_col=False))
and then pd.DataFrame.from_dict(Sach)
i got this Data Frame which is almost what i wanted but i only need the Cols and Values
Col1 Col2
Sheetname 0 Val1 Val2
1