gpt4 book ai didi

Python:使用 pandas 将一个数组连接到另一个数组

转载 作者:行者123 更新时间:2023-12-01 09:25:21 25 4
gpt4 key购买 nike

如何使用 pandas 得出 aoiFeatures 和 allFeaturesReadings 的合并结果,从而产生以下结果:

183  0.03
845 0.03
853 0.01

给定以下起始代码和数据:

import numpy
import pandas as pd
allFeatures = [101, 179, 181, 183, 185, 843, 845, 847, 849, 851, 853, 855]
allReadings = [0.03, 0.01, 0.01, 0.03, 0.03, 0.01, 0.03, 0.02, 0.07, 0.06, 0.01, 0.04]
aoiFeatures = [183, 845, 853]

allFeaturesReadings = zip(allFeatures, allReadings)
#
# Use pandas to create Series and Join here?
#
sAllFeaturesReadings = pd.Series(dict(allFeaturesReadings))
sAOIFeatures = pd.Series(numpy.ma.filled(aoiFeatures))
sIndexedAOIFeatures = sAOIFeatures.reindex(numpy.ma.filled(aoiFeatures))
result = pd.concat([sIndexedAOIFeatures,sAllFeaturesReadings], axis=1, join='inner')

最佳答案

无需压缩即可:

df = pd.DataFrame(data={"allFeatures":allFeatures, "allReadings":allReadings})
df[df["allFeatures"].isin(aoiFeatures)]

关于Python:使用 pandas 将一个数组连接到另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com