'Converting pandas dataframe to 3D array as input to LSTM model

Pandas dataframe:

id feature1 feature2
1 2234 13
1 2235 12
2 3344 12
2 3364 14
2 3354 9

Problem:

There are more than 2 features in the data on which model needs to be trained. Each id can have multiple rows, so need to group by id to get the sequence data for each id. And then convert it to 3d numpy array as required by LSTM model

Already tried Tried solution here, and it works for single feature though I need it for multiple features.

Appreciate any help here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source