2017-08-02 5 views
0

以下のように2つのデータフレームがあります(ここには2行しか表示されていません)。私が次のことをするとき:2つのパンダデータフレームを結合して追加の列を貼り付けるときのValueError

pd.concat([df1,df2],axis=1) 

私は以下に述べるようにValueErrorというエラーが発生します。私は私の問題を再現できるように、私が下で結合している2つのデータフレームを提供しました。私は現在、パンダのバージョン0.20.3を実行中です。

ValueError: Shape of passed values is (100, 41), indices imply (100, 34) 

私の問題は何か、私のポストを読んでいただきありがとうございます。

Sample_ID,NaX,MgX,AlX,SiX,PX,SX,ClX,ArX,KX,CaX,ScX,TiX,VX,CrX,MnX,FeX,CoX,NiX,CuX,ZnX,GaX,GeX,AsX,SeX,BrX,RbX,SrX,MoX,AgX,CdX,SnX,SbX,TeX,IX,CsX,BaX,LaX,CeX,SmX,WX,HgX,PbX,BiX,F,Cl,SO4,NO3,PO4,OCX,ECX 
 
87,10.725746036140102,0.0,0.07261398719691106,0.5645407440981668,0.054658528544583966,7.662756030743126,0.6353063752573382,,2.6024853011372926,2.7424322582804304,0.0,0.00681251225338293,0.003432661212944887,0.027867928031861798,0.032911299506265444,0.10065618879804547,0.0,0.023637833214063562,0.011253847761208545,0.040769453175283896,0.010493381277109984,0.0,0.0004964156215643375,0.0,0.029732127121353407,0.019154249568232466,0.,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1637115347712177,0.0,0.0,0.0,0.0,0.0,0.002429267935314843,0.0,0.5085779643234895,1.9102879673157627,176.34116754164242,1.578544065477313,0.1576303633916417,10.037629488375918,7.740915086053255 
 
88,10.736308070641469,0.0,0.07937368927778717,0.42939951265315196,0.05956987458772049,8.048270290043089,0.9627294447997737,,2.902447080976169,3.482830876826389,0.001267444140164266,0.03691431058228424,0.007488482461470538,0.02910368606852196,0.040325847726226396,0.11190475554200331,0.0,0.029520886431326027,0.013223667195713842,0.05830243044755624,0.010466976190856564,0.0,0.0004911346043136531,0.0,0.03509235963079812,0.022750622315948574,0.01617047482159576,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.008021865203789667,0.0,0.0,0.0,0.0037389602134845846,0.0,0.3782061849227544,0.1518159100550295,0.0,0.42525524770157946,0.0,12.028572991883953,8.35404118885772 
 
286,0.0,0.7250836685189738,0.6268567476562432,19.703475362303653,0.3058765191596428,4.056877451975788,0.8011303169288299,,8.101080462549932,1.5806084631298534,0.0010033932776300437,0.02232814093589382,0.0026352276080915363,0.0038181754722448513,0.12452638677113913,0.16334186356366978,0.0,0.011222161657704439,0.012563540039378285,0.10614844673875728,0.011713296262018091,0.0,0.0011987909159053684,0.0,0.005809118975752885,0.0354356257520926,0.013477156023746694,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0037495222479859533,0.0,0.3746855067556315,0.13810660264668706,0.0,0.40615823582536703,0.0,0.898829136066492,0.25771364183340073

Sample_ID,NaU,MgU,AlU,SiU,PU,SU,ClU,ArU,KU,CaU,ScU,TiU,VU,CrU,MnU,FeU,CoU,NiU,CuU,ZnU,GaU,GeU,AsU,SeU,BrU,RbU,SrU,MoU,AgU,CdU,SnU,SbU,TeU,IU,CsU,BaU,LaU,CeU,SmU,WU,HgU,PbU,BiU,FU,ClU,SO4U,NO3U,PO4U,OCU,ECU 
 
87,1.0194198489852335,0.0,0.003858856699020478,0.002418376010244413,0.00010916518701732756,0.007981852744327911,0.00042660280364963403,,0.0037123282280921883,0.0061975832384126685,0.0,0.00018575430466629458,0.00020779857121534524,0.00022244053455793694,0.000448113503393954,0.0006630148474327544,,0.0006727884955266499,0.0003196042031614733,7.580606419322902e-05,0.00035938350870231466,,0.0001103812637594452,,0.0003076902201744425,7.034706777428547e-05,0.00015976237933797543,,,,,,,,,,,0.0,,,,9.1207054999905e-05,,0.0210954298720446,0.47739999604201944,3.333354579661071,0.1111663019433814,0.019313942463642982,1.1891126335398214,1.7667352479080924 
 
88,1.0204237090039288,0.0,0.00421808117718384,0.0018394588717771116,0.00011897423280729031,0.00838342080107218,0.0006464645977167771,,0.004140210215420995,0.007870799433339409,0.00015158306425998205,0.0010065291392382938,0.0004533205753590147,0.0002323042990238375,0.0005490684711033748,0.0007371083219884607,,0.0008402340683632646,0.00037554618710292315,0.00010840659957166428,0.0003584791717403059,,0.00010920699499604687,,0.0003631619028524282,8.355532615705042e-05,0.00020834429537175506,,,,,,,,,,,0.0016572745295978877,,,,0.0001403795542172451,,0.015687706921837238,0.03794030852909965,0.0,0.029947883181016374,0.0,1.4249707189002216,1.9066710933727737 
 
286,0.0,0.11967400354196656,0.03331245746718042,0.08440562108720212,0.0006109031528544552,0.0042258161806979335,0.0005379521638707356,,0.011555826911309693,0.0035719943448043745,0.0001200032592058191,0.0006088133334334059,0.00015952536467147272,3.0476503029256854e-05,0.0016955257397351464,0.001075920736153992,,0.0003194091941452482,0.00035679887344962217,0.0001973707111766714,0.00040116387634712335,,0.0002665590092914262,,6.01170945278662e-05,0.00013014304515176608,0.00017364292677619819,,,,,,,,,,,0.0,,,,0.00014077610663028816,,0.01554167185035046,0.034514216016106464,0.0,0.02860300834674594,0.0,0.10648022845713559,0.05881885666387972

+0

パンダ0.20.1を使用して私にとってうまく動作します。なぜあなたはそのエラーメッセージを受け取っているのか分かりません – JohnE

答えて

0

私は今、問題を認識しています。私は両方のデータフレームに重複したインデックスを持っていました(実際は上記の例では表示されませんでした)。両方のデータフレームの私のインデックスは "Sample_ID"でした、私は本当に私のデータにそれらの重複した行が欲しいです。したがって、ここで1は「連結」を行う前に一度、私はデータフレーム、DF1とDF2の両方のためにやってしまったものです。その後、

Sample_ID=df.index.values 
df=df.reset_index(drop=True) 
df['Sample_ID']=Sample_ID 

そして、私はここのような連結をした:

Merged_df=pd.concat([df1,df2],axis=1) 

それがうまくいった!

関連する問題