是否可以在numpy.genfromtxt输出中添加新字段? [英] Is it possible to add a new field in a numpy.genfromtxt output?

查看:76
本文介绍了是否可以在numpy.genfromtxt输出中添加新字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载了一个csv文件,并使用标题指定了每一列的名称.

I loaded a csv file and used the header to specify the names of each column.

# Load the Data
data = np.genfromtxt('dat_h.csv',
                     delimiter=',',
                     names=True)

这很好,因为我可以按列名访问它们.例如...

This is great, because I can access the columns by their name. For example...

DATES = data['Dates']
Temperature = data['Temp']

说我有一个与这些测量值相匹配的压力观测向量.我可以在数据结构后面附加一个包含压力变量的新字段吗?

Say I have a vector of pressure observations that matches these measurements. Can I append the data structure with a new field that includes my pressure variable?

我想做这样的事情...

I want to do something like this ...

data.append('Pressure',pressure_vector)
# and then be able to access that field like I do the other fields
data['Pressure']

推荐答案

查看文档的功能.

主要我认为您需要的是这个

Mainly I think what you need is this:

from numpy.lib.recfunctions import append_fields

append_fields(data, 'Pressure', pressure_vector, np.double)

这篇关于是否可以在numpy.genfromtxt输出中添加新字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆