I want to concat 2 dataframes vertically, but I get this error:
Reindexing only valid with uniquely valued Index objects
How can I fix it?
df1
TimeStamp Input X Y Time Distance Speed Pressure Tilt_X Tilt_X
16 79769.0 aaaaa 8898 8438 NaN NaN NaN None None None
17 79784.0 aaaaa 8898 8438 15.0 0.0 0.0 None None None
18 79793.0 aaaaa 8898 8438 9.0 0.0 0.0 None None None
19 79802.0 aaaaa 8898 8438 9.0 0.0 0.0 None None None
df2
TimeStamp Input X Y Time Distance Speed Pressure Tilt_X Tilt_Y
26 84456.0 bbb 8762 9318 NaN NaN NaN 0 0 0
27 84459.0 bbb 8762 9318 3.0 0.0 0.0 4069 -1397 -1445
28 84459.0 bbb 8762 9318 0.0 0.0 0.0 4069 -1397 -1445
29 84464.0 bbb 8762 9318 5.0 0.0 0.0 3944 -1397 -1445
30 84472.0 bbb 8762 9318 8.0 0.0 0.0 3692 -1397 -1445
31 84482.0 bbb 8741 9253 10.0 0.6 0.0 3317 -1397 -1445
I want to concat to this:
TimeStamp Input X Y Time Distance Speed Pressure Tilt_X Tilt_X
16 79769.0 aaaaa 8898 8438 NaN NaN NaN None None None
17 79784.0 aaaaa 8898 8438 15.0 0.0 0.0 None None None
18 79793.0 aaaaa 8898 8438 9.0 0.0 0.0 None None None
19 79802.0 aaaaa 8898 8438 9.0 0.0 0.0 None None None
26 84456.0 bbb 8762 9318 NaN NaN NaN 0 0 0
27 84459.0 bbb 8762 9318 3.0 0.0 0.0 4069 -1397 -1445
28 84459.0 bbb 8762 9318 0.0 0.0 0.0 4069 -1397 -1445
29 84464.0 bbb 8762 9318 5.0 0.0 0.0 3944 -1397 -1445
30 84472.0 bbb 8762 9318 8.0 0.0 0.0 3692 -1397 -1445
31 84482.0 bbb 8741 9253 10.0 0.6 0.0 3317 -1397 -1445
But the following code results in Reindexing only valid with uniquely valued Index objects
:
aaaaa_tmp_df = pd.concat([aaaaah_Time_df,
aaaaa_input_df,
aaaaa_X_df,
aaaaa_Y_df,
aaaaa_time_df_diff,
aaaaa_xy_real_dis_df,
aaaaa_speed_df,
aaaaa_Pressure_df,
aaaaa_TiltX_df,
aaaaa_TiltY_df],axis = 1)
aaaaa_tmp_df.columns=['TimeStamp',
'Input',
'X',
'Y',
'Time',
'Distance',
'Speed',
'Pressure',
'Tilt_X',
'Tilt_X']
bbb_tmp_df = pd.concat([bbb_Time_df,
bbb_input_df,
bbb_X_df,
bbb_Y_df,
bbb_time_df_diff,
bbb_xy_real_dis_df,
bbb_speed_df,
bbb_Pressure_df,
bbb_TiltX_df,
bbb_TiltY_df],axis = 1)
bbb_tmp_df.columns=['TimeStamp',
'Input',
'X',
'Y',
'Time',
'Distance',
'Speed',
'Pressure',
'Tilt_X',
'Tilt_Y']
aaaaa = aaaaa_tmp_df[aaaaa_tmp_df['Input'] == 'aaaaa']
bbb = bbb_tmp_df[bbb_tmp_df['Input'] == 'bbb']
all_df = pd.concat([aaaaa,bbb],axis = 0, ignore_index=True)
Error msg:
Traceback (most recent call last):
File "D:\Python\Digiinfo_Parser\Digiinfo_Parser.py", line 276, in
<module>
all_df = pd.concat([touch,pen,ptp],axis = 0, ignore_index=True)
File "C:\Users\ANDYCHEN\Anaconda3\lib\site-
packages\pandas\core\reshape\concat.py", line 298, in concat
return op.get_result()
File "C:\Users\ANDYCHEN\Anaconda3\lib\site-
packages\pandas\core\reshape\concat.py", line 516, in get_result
indexers[ax] = obj_labels.get_indexer(new_labels)
File "C:\Users\ANDYCHEN\Anaconda3\lib\site-
packages\pandas\core\indexes\base.py", line 3171, in get_indexer
raise InvalidIndexError(
InvalidIndexError: Reindexing only valid with uniquely valued Index
objects