I need to reorgannise my Data again. I have two Dataframes:df1 and df2 and i want df3
df1 df2 df3
1 2 3 1 2 3 a 1 b 4 c 7
1 a b c 1 1 2 3 d 1 e 4 f 7
2 d e f 2 4 5 6 g 1 h 4 i 7
3 g h i 3 7 8 9 a 2 b 5 c 8
d 2 e 5 f 8
g 2 h 5 i 8
a 3 b 6 c 9
d 3 e 6 f 9
g 3 h 6 i 9
So the Logic of df3 should be like matrix multiplikation. I did try to modify and Answer given to my yesterdays Question which was:
a,b = df.shape
m = int(a/2)
x = pd.DataFrame(df.iloc[:m,np.r_[m:b]].to_numpy()).T
y = pd.DataFrame(df.iloc[m:,:m].to_numpy())
out = (pd.concat((y,x),axis=1).sort_index(axis=1)
.set_axis(df.columns,axis=1,inplace=False))
I did implement this code sucessfully, but the modification by myself does not get me the wanted result. Any Recomendation is welcome and appreciated. Please Consider the following Information:
- 3x3 is exemplary , so the given Dataframe Shapes may Vary by size and Shape
- Both given Dataframes will always have same Shape and Size
- Yesterdays Question -> Goodanswer -> Wrong Question my Bad Reorganize elements of Pandas Dataframe by row and column to new dataframe
- I know theres a Way to get automatically a result matrix from matrix multiplication in pandas. i already have this implemented and used in my Script.
- Using only Numbers in df1 and only letters in df2 is to make it easier to understand what try to do. in words the needed Datastructure could be described as:
I Hope this big Post, could Clarify my Problem. As i am new here i also appreciate critics on the way i ask for Help and improve my Communication on Stack-Overflow.
A small UPDATE: I found this Pandas concatenate alternating columns Thread which is quite close to what i want to do. As I have to work in a couple of minutes i cant give it a try. But for alle people, who want to contribute to my Question, this might make it easier and give some Inspriation.
I will work on this tomorrow and keep you guys updated.
kind Regards and thanks in Advance,
Hans Peter