Reputation: 465
I am trying to splice to dataframes together. I have a list of which rows that contain data that matches between the two dataframes.
So let's say that row 300 from dataframe 1 refers to the same company as row 2 from dataframe 2. At the moment I am creating a new dataframe with the two original ones, but it is not adding them in the right way.
df_final = pd.DataFrame( df1.iloc[300], df2.iloc[2]])
Doing this I get two rows with data from both dataframes, where what I really want is one row, with the data from both, added horizontally. So if each dataframe has 5 columns I want something that has 10 columns.
import pandas as pd
position_list = [(0, 85, 83),
(1, 134, 67),
(2, 78, 50),
(3, 89, 83),
(4, 90, 83),
(5, 91, 83)]
ammended_results= Name of Applicant CMU ID CMU Name Capacity Awarded Classification Capacity (MW) Duration (Years) Clearing price (£) Yearly CMU Funding (£) Contract Length Funding (£) New Generation Existing Generation New Capacity Existing Capacity
1 SSE Generation Ltd. BURGH1 Burghfield Yes Existing Generating CMU 44.034 1.0 19.4 854259.6 854259.6 0 1 0.000 44.034
2 SSE Generation Ltd. CBEU01 Deanie 1 Yes Existing Generating CMU 15.886 1.0 19.4 308188.4 308188.4 0 1 0.000 15.886
3 SSE Generation Ltd. CBEU02 Deanie 2 Yes Existing Generating CMU 15.886 1.0 19.4 308188.4 308188.4 0 1 0.000 15.886
...
ammended_register = Unique CMU Identifier Type Delivery Year Name of Applicant CM Unit Name
...
BURG18 T-4 2018 SSEPG (Operations) Limited Burghfield
...
Basically I want to the first entry from the results dataframe with the 85th entry in the register dataframe. And create a new dataframe with all this information.
At the moment I am using this
df_list=[]
for i in range(len(position_list)):
result = position_list[i][1]
df_final = pd.concat(ammended_results.iloc[i], ammended_register.iloc[results]])
df.reset_index(inplace=True, drop=True)
df_list.append(df)
fr = pd.concat(df_list, axis=0)
but the final dataframe I am getting is not adding them in the right way
Upvotes: 0
Views: 2041
Reputation: 19375
easy peasy lemon squeezy
pd.concat([ df1.iloc[300], df2.iloc[2]], axis = 1)
Upvotes: 2