我有两个x值略有不同的数据集。 我想用相同的x值减去两个数据集的y值。以下是数据的样子:
第一个数据:
data1_x data1_y1 data1_y2 data1_y3
-566.692382 0 0 0
-456.971091 0 0 0
-347.2498 0 0 0
-237.528509 0 0 0
-127.807218 0 0 0
-18.085927 0 0 0
91.635364 0 0 0
201.356655 0 0 0
311.077946 0 0 0
420.799237 0 0 0
530.520528 0 0 0
640.241819 0 0 0
749.96311 0 0 0
859.684401 0 0 0
969.405692 0 0 0
1079.126983 0 0 0
1188.848274 0 0 0
1298.569565 0 0 0
1408.290856 0 0 0
1518.012147 0 0 0
1627.733439 0 0 0
1737.45473 0 0 0
1847.176021 0 0 0
1956.897312 0 0 0
2066.618603 0 0 0
2176.339894 0 0 0
2286.061185 0 0 0
2395.782476 0 0 0
2505.503767 0 0 0
2615.225058 0 0 0
2724.946349 0 0 0
2834.66764 0 0 0
2944.388931 0 0 0
3054.110222 0 0 0
3163.831513 0.000756 0 0.000225
3273.552804 0.007979 0 0.005741
3383.274095 0.155249 0 0.141201
3492.995386 1 0 0.987494
3602.716677 0.966901 0 1
3712.437968 0.155149 0 0.160298
3822.159259 0.013988 0 0.013816
3931.88055 0.004039 0 0.002835
4041.601841 0.002268 0.029346 0.002405
4151.323132 0.000577 0.028708 0.000225
4261.044424 0.000298 0.336204 0.000256
4370.765715 0 0.889952 0.000307
4480.487006 0 1 0.000133
4590.208297 0 0.73429 0.000194
4699.929588 0 0.540032 0
4809.650879 0 0.481659 0
4919.37217 0 0.227113 0
5029.093461 0 0.155662 0
5138.814752 0 0.051675 0
5248.536043 0 0.023285 0
5358.257334 0.000318 0.035726 0
5467.978625 0 0 0
5577.699916 0 0.016268 0
5687.421207 0 0 0.000133
5797.142498 0 0 0
5906.863789 0 0.026794 0
6016.58508 0 0.004466 0
6126.306371 0 0.004466 0
6236.027662 0 0 0
6345.748953 0 0 0
6455.470244 0 0 0
6565.191535 0 0 0
6674.912826 0 0 0
6784.634117 0 0 0
6894.355408 0 0 0
7004.0767 0 0 0
7113.797991 0 0 0
7223.519282 0 0 0
7333.240573 0 0 0
7442.961864 0 0 0
7552.683155 0 0 0
7662.404446 0 0 0
7772.125737 0 0 0
7881.847028 0 0 0
7991.568319 0 0 0
8101.28961 0 0 0
8211.010901 0 0 0
8320.732192 0 0 0
8430.453483 0 0 0
8540.174774 0 0 0
8649.896065 0 0 0
8759.617356 0 0 0
8869.338647 0 0 0
8979.059938 0 0 0
9088.781229 0 0 0
9198.50252 0 0 0
9308.223811 0 0 0
9417.945102 0 0 0
9527.666393 0 0 0
9637.387685 0 0 0
9747.108976 0 0 0
9856.830267 0 0 0
9966.551558 0 0 0
10076.27285 0 0 0
10185.99414 0 0 0
10295.71543 0 0 0
10405.43672 0 0 0
10515.15801 0 0 0
10624.8793 0 0 0
10734.6006 0 0 0
10844.32189 0 0 0
10954.04318 0 0 0
11063.76447 0 0 0
11173.48576 0 0 0
11283.20705 0 0 0
11392.92834 0 0 0
11502.64963 0 0 0
11612.37092 0 0 0
11722.09221 0 0 0
11831.81351 0 0 0
11941.5348 0 0 0
12051.25609 0 0 0
12160.97738 0 0 0
12270.69867 0 0 0
12380.41996 0 0 0
12490.14125 0 0 0
12599.86254 0 0 0
12709.58383 0 0 0
12819.30513 0 0 0
12929.02642 0 0 0
13038.74771 0 0 0
13148.469 0 0 0
13258.19029 0 0 0
13367.91158 0 0 0
13477.63287 0 0 0
13587.35416 0 0 0
13697.07545 0 0 0
13806.79674 0 0 0
13916.51804 0 0 0
14026.23933 0 0 0
14135.96062 0 0 0
14245.68191 0 0 0
14355.4032 0 0 0
14465.12449 0 0 0
14574.84578 0 0 0
14684.56707 0 0 0
14794.28836 0 0 0
14904.00965 0 0 0
15013.73095 0 0 0
15123.45224 0 0 0
15233.17353 0 0 0
15342.89482 0 0 0
15452.61611 0 0 0
15562.3374 0 0 0
15672.05869 0 0 0
15781.77998 0 0 0
15891.50127 0 0 0
16001.22257 0 0 0
16110.94386 0 0 0
16220.66515 0 0 0
16330.38644 0 0 0
16440.10773 0 0 0
16549.82902 0 0 0
16659.55031 0 0 0
16769.2716 0 0 0
16878.99289 0 0 0
16988.71418 0 0 0
17098.43548 0 0 0
17208.15677 0 0 0
17317.87806 0 0 0
17427.59935 0 0 0
17537.32064 0 0 0
17647.04193 0 0 0
17756.76322 0 0 0
17866.48451 0 0 0
17976.2058 0 0 0
18085.9271 0 0 0
18195.64839 0 0 0
18305.36968 0 0 0
18415.09097 0 0 0
18524.81226 0 0 0
18634.53355 0 0 0
18744.25484 0 0 0
18853.97613 0 0 0
18963.69742 0 0 0
19073.41871 0 0 0
19183.14001 0 0 0.000297
19292.8613 0 0 0
19402.58259 0 0 0
19512.30388 0 0 0
19622.02517 0 0 0
19731.74646 0 0 0
19841.46775 0 0 0
19951.18904 0 0 0
20060.91033 0 0 0
20170.63162 0 0 0
20280.35292 0 0 0
20390.07421 0 0 0
20499.7955 0 0 0
20609.51679 0 0 0
20719.23808 0 0 0
20828.95937 0 0 0
20938.68066 0 0 0
21048.40195 0 0 0
21158.12324 0 0 0
21267.84454 0 0 0
第二个数据看起来像
data2_x data2_y1 data2_y2 data2_y3
-613.863532 0 0 0
-504.331019 0 0 0
-394.798507 0 0 0
-285.265994 0 0 0
-175.733482 0 0 0
-66.200969 0 0 0
43.331543 0 0 0
152.864056 0 0 0
262.396569 0 0 0
371.929081 0 0 0
481.461594 0 0 0
590.994106 0 0 0
700.526619 0 0 0
810.059131 0 0 0
919.591644 0 0 0
1029.124156 0 0 0
1138.656669 0 0 0
1248.189181 0 0 0
1357.721694 0 0 0
1467.254207 0 0 0
1576.786719 0 0 0
1686.319232 0 0 0
1795.851744 0 0 0
1905.384257 0 0 0
2014.916769 0 0 0
2124.449282 0 0 0
2233.981794 0 0 0
2343.514307 0 0 0
2453.04682 0 0 0
2562.579332 0 0 0
2672.111845 0 0 0
2781.644357 0 0 0
2891.17687 0 0 0
3000.709382 0 0.00421 0
3110.241895 0 0 0
3219.774407 0 0.000472 0.000258
3329.30692 0.005998 0.005817 0.046254
3438.839433 0.126953 0.025986 0.447706
3548.371945 0.595733 0.007664 1
3657.904458 0.977669 0.010667 0.981762
3767.43697 0.846061 0.000766 0.481531
3876.969483 0.787706 0 0.182611
3986.501995 1 0 0.102414
4096.034508 0.964644 0.03512 0.051297
4205.56702 0.54548 0.161153 0.017741
4315.099533 0.178064 0.558853 0.003784
4424.632045 0.037034 0.789553 0.001666
4534.164558 0.007972 0.96508 0.000394
4643.697071 0.003013 1 0
4753.229583 0.002961 0.903092 0.000163
4862.762096 0.002831 0.669578 0.000293
4972.294608 0.001025 0.375463 0.000108
5081.827121 0.000761 0.251614 0.000161
5191.359633 0 0.139304 0
5300.892146 0 0.044527 0
5410.424658 0.000413 0.008105 0
5519.957171 0 0.003013 6.50E-05
5629.489684 0 0 0
5739.022196 0.000211 0.003381 0
5848.554709 0 0.003633 0
5958.087221 0 0.004651 0.000121
6067.619734 0 0.017901 0
6177.152246 0 0.001134 0
6286.684759 0 0.002394 0
6396.217271 0 0.000462 0
6505.749784 0 0 0
6615.282297 0 0 0
6724.814809 0 0 0
6834.347322 0 0.000504 0
6943.879834 0 0.002016 0
7053.412347 0 0.004326 0
7162.944859 0.000185 0.00546 6.00E-05
7272.477372 0 0 0
7382.009884 0 0 0
7491.542397 0 0 0
7601.074909 0 0 0.000131
7710.607422 0 0 0
7820.139935 0 0 0
7929.672447 0 0 0
8039.20496 0 0 0
8148.737472 0 0 0
8258.269985 0 0 0
8367.802497 0.000273 0 0
8477.33501 0 0 0
8586.867522 0 0.001522 0
8696.400035 0 0 0
8805.932548 0 0 0.000133
8915.46506 0 0 0
9024.997573 0 0 0
9134.530085 0 0 7.20E-05
9244.062598 0 0 0
9353.59511 0 0 0
9463.127623 0 0 0
9572.660135 0 0 0
9682.192648 8.50E-05 0 0
9791.725161 0 0 0
9901.257673 0 0 0
10010.79019 0 0 0
10120.3227 0 0 6.60E-05
10229.85521 0 0 0.000128
10339.38772 0 0 0
10448.92024 0 0 0
10558.45275 0 0 0
10667.98526 0 0 0
10777.51777 0 0 6.60E-05
10887.05029 0 0 6.70E-05
10996.5828 0 0 3.00E-05
11106.11531 0 0 0
11215.64782 0 0 0
11325.18034 0 0 0
11434.71285 0 0 0
11544.24536 0 0 0
11653.77787 0 0 0
11763.31039 0 0 0
11872.8429 0 0 0
11982.37541 0 0 0
12091.90792 0 0 0
12201.44044 0 0 0
12310.97295 0 0 0
12420.50546 0 0 0
12530.03797 0 0 0
12639.57049 0 0 0
12749.103 0 0 0
12858.63551 0 0 0
12968.16803 0 0 0
13077.70054 0 0 0
13187.23305 0 0 0
13296.76556 0 0 0
13406.29808 0 0 0
13515.83059 0 0 0
13625.3631 0 0 0.00011
13734.89561 0 0 0
13844.42813 0 0 0
13953.96064 0 0 0
14063.49315 0 0 0
14173.02566 0 0 0
14282.55818 0 0 0
14392.09069 0 0 0
14501.6232 0 0 0
14611.15571 0 0 0
14720.68823 0 0 0
14830.22074 0 0 0
14939.75325 0.000177 0 0
15049.28576 0 0 0
15158.81828 0 0 0
15268.35079 0 0 0
15377.8833 0 0 0
15487.41581 0.00017 0 0
15596.94833 0 0 0
15706.48084 0 0 0
15816.01335 0 0 4.80E-05
15925.54586 0 0 0
16035.07838 0 0 0
16144.61089 0 0 0
16254.1434 0.000216 0 0
16363.67591 0 0 0
16473.20843 0 0 0
16582.74094 0 0 0
16692.27345 0.000239 0 0
16801.80596 0 0 0
16911.33848 0 0 0
17020.87099 0 0 0
17130.4035 0 0 0
17239.93601 0 0 0
17349.46853 0 0 0
17459.00104 0 0 0
17568.53355 0 0 6.10E-05
17678.06606 0 0 4.50E-05
17787.59858 0 0 0
17897.13109 0 0 0
18006.6636 0 0 0
18116.19611 0.000125 0 0
18225.72863 0 0 0
18335.26114 0 0 0
18444.79365 0 0 0
18554.32617 0 0 0
18663.85868 0 0 0
18773.39119 0 0 0
18882.9237 0 0 0
18992.45622 0 0 0
19101.98873 0 0 0
19211.52124 0 0 0
19321.05375 0 0 0
19430.58627 0 0 0
19540.11878 0 0 0
19649.65129 0 0 0
19759.1838 0 0 0
19868.71632 0 0 0
19978.24883 0 0 0
20087.78134 0 0 0
20197.31385 0 0 0
20306.84637 0 0 0
20416.37888 0 0 0
20525.91139 0 0 0
20635.4439 0 0 0
20744.97642 0 0 0
20854.50893 5.20E-05 0 0
20964.04144 0 0 0
21073.57395 0 0 0
21183.10647 0 0 0
如您所见,x值并不完全相同。鉴于此,data1-data2
不会产生我想要的结果。我可以使用插值法将y值推定为相同的x值。例如,我可以使用以下代码进行插值:
Interpolation = interp1d(data1_y, data1_x, assume_sorted = False)
我仍然没有想出如何使用插值法将相同x处的两个数据的y值相减...有什么想法吗?
编辑1):
我的意思是data1-data2
是这样。
data1=pd.read_csv('Data1.csv')
data2=pd.read_csv('Data2.csv')
data1.iloc[:,1:]-data2.iloc[:,1:] #this line is what I meant by data1-data2
很抱歉,我的描述不充分。没关系,
data1.iloc[:,1:]-data2.iloc[:,1:]
将不起作用,因为它将从相同的索引号中减去这些值。但是,对于每个数据集,相同索引号中的y值具有不同的对应x值。