I can't seem to figure this out - I have a dataframe that I'm trying to iterate on each row but when I iterate it is converting my dataframe into a series.
df = pd.DataFrame(np.random.rand(5, 5)*10, columns=list('ABCDE')).astype(int)
for index, row in df.iterrows():
print(row['A'],row['B'] )
print("Row shape - ", row.shape)
print("Row type - ", type(row))
print("DF shape - ", df.shape)
print("DF type - ", type(df))
0 1
6 1
6 4
9 6
6 2
Row shape - (5,)
Row type - <class 'pandas.core.series.Series'>
DF shape - (5, 5)
DF type - <class 'pandas.core.frame.DataFrame'>
I tried to_frames but it didn't work:
print("row after to frame ", row.to_frame().shape)
row after to frame (5, 1)
My problem is, I need to send it to a function one row at a time(therefore using iterrows()) and need it to retain the same structure as the dataframe I'm iterrows.
The problem when I send it to the other function(transform using an existing scaler), it's rejecting it because it's shape is different than the dataframes. So in my example, for each row I'd like to send it in a shape like this (1, 5) instead of (5,).
Is that possible?