1

I have single data frame which consist of multiple columns name such as "Load_Node_Values,Load_KV_Values,Load_Node_Values,Load_KV_Values,Load_P_ST_Values,Load_ST_Values,G_Node_Values,G_KV_Values,G_P_ST_Values,G_ST_Values,Line_Node_Values,Line_KV_Values,Line_P_ST_Values,Line_ST_Values,T_Node_Values,T_KV_Values,T_P_ST_Values,T_ST_Values,Load_P_ST_Values,Load_ST_Values,G_Node_Values G_KV_Values,G_P_ST_Values,G_ST_Values,Line_Node_Values,Line_KV_Values,Line_P_ST_Values,Line_ST_Values,T_Node_Values,T_KV_Values". All these columns have have numeric as well as string values. I want to combine all the values of Load_Node_values, G_Node_values, Line_Node_values and T_Node_Values into one one single column "new name" and similarly, other column as well into another new column name.

This is how the dataset looks like

I used frames and put all the columns that want to combine. In the code I showed that frame_node, frame_KV, frame_P, frame_ST and put all the columns names in these frames as shown in the code.

frame_KV=[df1['Load_KV_Values'],df2['G_KV_Values'],df3['Line_KV_Values'],df4['T_KV_Values']]
frame_P=[df1['Load_P_ST_Values'],df2['G_P_ST_Values'],df3['Line_P_ST_Values'],df4['T_P_ST_Values']]
frame_ST=[df1['Load_ST_Values'],df2['G_ST_Values'],df3['Line_ST_Values'],df4['T_ST_Values']]

frames=[frame_node,frame_KV,frame_P,frame_ST]

result_nodes=pd.concat(frames)

This is error I got from the text. "TypeError: cannot concatenate object of type ""; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid"

2 Answers 2

1
frame_1=df1[['Load_KV_Values','Load_P_ST_Values','Load_ST_Values']]
frame_2= df2[['G_P_ST_Values','G_KV_Values','G_ST_Values']]
frame_3=df3[['Line_KV_Values','Line_ST_Values','Line_P_ST_Values']
frame_4 = df4[['T_KV_Values','T_P_ST_Values','T_ST_Values']
result_nodes = pd.concat([frame_1, frame_2, frame_3, frame_4], axis =1)

Please check by following method anlso please verify wether all four dataframes have same number of rows. --Do upvote

Sign up to request clarification or add additional context in comments.

2 Comments

No, these data frames does not have same number of rows. and it shows the same result as it was previous. I need to combine all the Node values in the same column, similarly,all KV Values and ST Values in the same column
If you dont have same number of rows in all dataframes, then you cant combine(concatenate) .
0

There is list of list of Series, so flatten it for list of Series:

result_nodes=pd.concat([y for x in frames for y in x])

Or maybe need first concat by axis=1 fr eacj list and then by default axis=0 (should be omit):

result_nodes=pd.concat(pd.concat([x for x in frames], axis=1))

2 Comments

frame_KV=[df1['Load_KV_Values'],df2['G_KV_Values'],df3['Line_KV_Values'],df4['T_KV_Values']] Is this code right for combine these multiple column as row wise becuause I didn't fetch the right result
@anmol - I think yes, only need same index values in all DataFrames, so try df1 = df1.reset_index(drop=True), df2 = df2.reset_index(drop=True), df3 = df3.reset_index(drop=True), df4 = df4.reset_index(drop=True) befoire your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.