Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于其他列的段位置,在Panda列中使用Python切片Ndarray_Python_Arrays_Pandas_Slice - Fatal编程技术网

基于其他列的段位置,在Panda列中使用Python切片Ndarray

基于其他列的段位置,在Panda列中使用Python切片Ndarray,python,arrays,pandas,slice,Python,Arrays,Pandas,Slice,我有一个熊猫数据框,其中一列中存储了一个2d数组:“mels” 在Dataframe的其他列中,我有要从2d数组“mels”中提取的列的起始位置和结束位置。 以下是我的数据框的外观: ## Data Frame which has Start Location of a segment : HS_Start ## & end location of a segment : HS_End df_sound_loc.ix[:,-3:].head(5)[enter image descrip

我有一个熊猫数据框,其中一列中存储了一个2d数组:“mels” 在Dataframe的其他列中,我有要从2d数组“mels”中提取的列的起始位置和结束位置。 以下是我的数据框的外观:

## Data Frame which has Start Location of a segment : HS_Start 
## & end location of a segment : HS_End
df_sound_loc.ix[:,-3:].head(5)[enter image description here][1]
HS|U开始| HS|U结束| mels| ---------| -------|------- ---13 |--25 |[0.0752865622903,0.004392394838,0.0182232|

例如,HS_Start:13和HS_End是25,那么我希望各个“mels”数组中的所有行都具有13到25列值: mels[:,13:25]

对于所有行,依此类推

# Column mels is a 2D array of 128 rows and 680 columns
df_sound_loc.ix[1,-1].shape
只想从mels:2d数组中提取HS_开始号和HS_结束号之间的列

print(df_sound_loc['mels'][:,df_sound_loc['HS_Start']:df_sound_loc['HS_End']])
出现以下错误:

如果包含密钥,则现在应该已经返回了

我不熟悉Python和数据帧操作。请建议您需要使用axis=1来按行处理:

df1['new'] = df1.apply(lambda x: x['mels'][:, x['HS_Start']:x['HS_End']].tolist(),axis=1)
对于按行处理,您需要使用轴=1:

df1['new'] = df1.apply(lambda x: x['mels'][:, x['HS_Start']:x['HS_End']].tolist(),axis=1)

欢迎来到StackOverflow。请花时间阅读这篇文章,以及如何提供答案并相应地修改您的问题。这些关于的提示可能也很有用。HS_Start HS_End mels 0 13 25[[0.0752865622903,0.004392394538,0.0182232…1 34 46[[0.0752865622903,0.00439454838,0.0182232…2 62 74[[0.0752865622903, 0.00439239454838, 0.0182232... 3 86 98 [[0.0752865622903, 0.00439239454838, 0.0182232... 4 117 129 [[0.0752865622903,0.004392394838,0.0182232…请用数据编辑问题。最好的方法是创建所需的输出。@jezrael添加了数据示例和所需的结果。欢迎使用StackOverflow。请花些时间阅读这篇文章以及如何提供答案并相应地修改你的问题。上的这些提示可能也很有用。HS_Start HSúEnd mels 0 13 25[[0.0752865622903,0.004392394838,0.0182232…1 34 46[[0.0752865622903,0.004392394838,0.0182232…2 62 74[[0.0752865622903,0.004392394838,0.0182232…386[[0.0752865622903,0.004392394838,0.0182232…请用数据编辑问题。最好的方法是创建所需输出。@jezrael添加了数据示例和所需结果。
df1['new'] = df1.apply(lambda x: x['mels'][:, x['HS_Start']:x['HS_End']].tolist(),axis=1)