I am a newB python modeller and currently experiencing some issues with a line of code which may be very basic for a lot of you.
I am using python 2.7 and have successfully used xlwings to copy a named range from external workbook in to the pd.dataframe format. Everything thing works fine except the df.index and df.columns. Currently the code is assigning 1 to n (based on number of rows and columns) numbers as a index and column names.
is there a way, I use the first column values of my imported data as df.index and first row as df.column?
Can some one please assist me with getting something like this:
df = pd.DataFrame(myExcelRange, df.index = 'first column values', df.columns = 'first row values')
The shape and name of myExcelRange could be different each time.
Any guideline will be much appreciated.
Example:
> myExcelRange
ITEM Dan Jane Fan
A 77 78 40
B 89 53 72
C 20 19 79
D 81 54 93
E 77 76 99
pandas is returning
0 1 2 3
0 ITEM Dan Jane Fan
1 77 78 40 0
2 89 53 72 0
3 20 19 79 0
4 81 54 93 0
5 77 76 99 0
desired
ITEM Dan Jane Fan
A 76 89 100
B 59 72 24
C 69 73 19
D 70 92 43
E 65 94 30
type(myExcelRange)?myExcelRange = ['a','b','c']ormyExcelRange = [['a','b','c'],['d','e','f']]and desired output?df = pd.DataFrame(myExcelRange).iat[0,0]ordf = pd.DataFrame(myExcelRange).iloc[0,0]? Or rename only first index value and first column value?