Tengo dos dataframes los cuales estoy comparando, para ver si el 'start' y 'end' de df1 están dentro del rango 'start' y 'end' de df2. Si están dentro del rango, lo que he hecho es adicionar una nueva columna llamada 'Genes into LCBs', en la cual se adiciona el valor 'genes lcbs'. Sin embargo observo que, el primer rango (977715 a 985708) no le es asignado el valor 'genes lcbs' en el df1, y no entiendo el por qué?, algo se me escapa y no lo veo.
df1
SEQ_NAME START END
NC_017357 975761 976096
NC_017357 976444 977268
NC_017357 977410 977604
NC_017357 977775 979698
NC_017357 979691 981621
NC_017357 981751 982736
NC_017357 982736 984003
NC_017357 984000 985235
NC_017357 985320 985616
NC_017357 985606 985869
NC_017357 985866 986165
NC_017357 986165 987105
NC_017357 987102 987557
NC_017357 987554 987844
NC_017357 987845 988402
NC_017357 988403 990145
NC_017357 990385 990667
NC_017357 990660 991750
NC_017357 992124 992560
NC_017357 992613 993042
NC_017357 993352 994480
NC_017357 994662 994880
NC_017357 994873 995067
NC_017357 995141 996988
NC_017357 997002 998171
NC_017357 998176 998604
NC_017357 998621 999406
NC_017357 999410 1000429
NC_017357 1000430 1002385
NC_017357 1002555 1003724
NC_017357 1003727 1005598
NC_017357 1006281 1006357
NC_017357 1006380 1006456
NC_017357 1006516 1006592
NC_017357 1006659 1006736
NC_017357 1006920 1007669
NC_017357 1007753 1009279
NC_017357 1009276 1009767
NC_017357 1009948 1012338
NC_017357 1012442 1013032
NC_017357 1013058 1014380
NC_017357 1014399 1014713
NC_017357 1014795 1015781
NC_017357 1015781 1018075
NC_017357 1018090 1019379
NC_017357 1019381 1020193
NC_017357 1020315 1021973
NC_017357 1022002 1022538
NC_017357 1022554 1024128
NC_017357 1024138 1025988
NC_017357 1026011 1026679
NC_017357 1026681 1027439
NC_017357 1027443 1028381
NC_017357 1028437 1030868
NC_017357 1030865 1031362
NC_017357 1031619 1032119
NC_017357 1032341 1032982
NC_017357 1033036 1033767
NC_017357 1033829 1035688
NC_017357 1035673 1035909
NC_017357 1035922 1036149
NC_017357 1036348 1037094
NC_017357 1037361 1037885
NC_017357 1038066 1039290
NC_017357 1039287 1040117
NC_017357 1040183 1041529
NC_017357 1041543 1042147
NC_017357 1042157 1044967
df2
977715 985708
-985709 -990725
991992 1042023
Mi salida:
SEQ_NAME START END Genes Into LCBs
NC_017357 975761 976096
NC_017357 976444 977268
NC_017357 977410 977604
NC_017357 977775 979698
NC_017357 979691 981621
NC_017357 981751 982736
NC_017357 982736 984003
NC_017357 984000 985235
NC_017357 985320 985616
NC_017357 985606 985869
NC_017357 985866 986165 genes LCBs
NC_017357 986165 987105 genes LCBs
NC_017357 987102 987557 genes LCBs
NC_017357 987554 987844 genes LCBs
NC_017357 987845 988402 genes LCBs
NC_017357 988403 990145 genes LCBs
NC_017357 990385 990667 genes LCBs
NC_017357 990660 991750
NC_017357 992124 992560 genes LCBs
NC_017357 992613 993042 genes LCBs
NC_017357 993352 994480 genes LCBs
NC_017357 994662 994880 genes LCBs
NC_017357 994873 995067 genes LCBs
NC_017357 995141 996988 genes LCBs
NC_017357 997002 998171 genes LCBs
NC_017357 998176 998604 genes LCBs
NC_017357 998621 999406 genes LCBs
NC_017357 999410 1000429 genes LCBs
NC_017357 1000430 1002385 genes LCBs
NC_017357 1002555 1003724 genes LCBs
NC_017357 1003727 1005598 genes LCBs
NC_017357 1006281 1006357 genes LCBs
NC_017357 1006380 1006456 genes LCBs
NC_017357 1006516 1006592 genes LCBs
NC_017357 1006659 1006736 genes LCBs
NC_017357 1006920 1007669 genes LCBs
NC_017357 1007753 1009279 genes LCBs
NC_017357 1009276 1009767 genes LCBs
NC_017357 1009948 1012338 genes LCBs
NC_017357 1012442 1013032 genes LCBs
NC_017357 1013058 1014380 genes LCBs
NC_017357 1014399 1014713 genes LCBs
NC_017357 1014795 1015781 genes LCBs
NC_017357 1015781 1018075 genes LCBs
NC_017357 1018090 1019379 genes LCBs
NC_017357 1019381 1020193 genes LCBs
NC_017357 1020315 1021973 genes LCBs
NC_017357 1022002 1022538 genes LCBs
NC_017357 1022554 1024128 genes LCBs
NC_017357 1024138 1025988 genes LCBs
NC_017357 1026011 1026679 genes LCBs
NC_017357 1026681 1027439 genes LCBs
NC_017357 1027443 1028381 genes LCBs
NC_017357 1028437 1030868 genes LCBs
NC_017357 1030865 1031362 genes LCBs
NC_017357 1031619 1032119 genes LCBs
NC_017357 1032341 1032982 genes LCBs
NC_017357 1033036 1033767 genes LCBs
NC_017357 1033829 1035688 genes LCBs
NC_017357 1035673 1035909 genes LCBs
NC_017357 1035922 1036149 genes LCBs
NC_017357 1036348 1037094 genes LCBs
NC_017357 1037361 1037885 genes LCBs
NC_017357 1038066 1039290 genes LCBs
NC_017357 1039287 1040117 genes LCBs
NC_017357 1040183 1041529 genes LCBs
NC_017357 1041543 1042147
NC_017357 1042157 1044967
Yo esperaría que, las lineas del 5 al 11 también tuvieran el valor 'genes LCBS', sin embargo no es así.
Mi código:
import pandas as pd
ivt = pd.read_csv('ivt_nc_017357.csv', sep=";")
tmp_df1 = pd.DataFrame(ivt)
df1= tmp_df1.drop(tmp_df1.columns[0], axis=1)
mochifile= pd.read_csv('NC_017357.csv', sep=";")
df2 = pd.DataFrame(mochifile)
for i in range(0, len(df2)):
for j in range(0, len(df1)):
if df2.iloc[i, 1] >= df1.iloc[j, 0] and df2.iloc[i, 2] <= df1.iloc[j, 1]:
df2.loc[i, 'Genes Into LCBs']= 'genes LCBs'
elif df2.iloc[i, 1] >= df1.iloc[j, 0]* -1 and df2.iloc[i, 2] <= df1.iloc[j, 1]* -1:
df2.loc[i, 'Genes Into LCBs']= 'genes LCBs'
outfile = df2.to_csv('Mochi_lcbs_tmp.csv', sep=";")