I am so confused with different indexing methods using iloc in pandas.
Let say I am trying to convert a 1-d Dataframe to a 2-d Dataframe. First I have the following 1-d Dataframe
a_array = [1,2,3,4,5,6,7,8]
a_df = pd.DataFrame(a_array).T
And I am going to convert that into a 2-d Dataframe with the size of 2x4. I start by preseting the 2-d Dataframe as follow:
b_df = pd.DataFrame(columns=range(4),index=range(2))
Then I use for-loop to help me converting a_df (1-d) to b_df (2-d) with the following code
for i in range(2):
b_df.iloc[i,:] = a_df.iloc[0,i*4:(i+1)*4]
It only gives me the following results
0 1 2 3
0 1 2 3 4
1 NaN NaN NaN NaN
But when I changed b_df.iloc[i,:] to b_df.iloc[i][:]. The result is correct like the following, which is what I want
0 1 2 3
0 1 2 3 4
1 5 6 7 8
Could anyone explain to me what the difference between .iloc[i,:] and .iloc[i][:] is, and why .iloc[i][:] worked in my example above but not .iloc[i,:]