【发布时间】:2017-05-21 21:29:25
【问题描述】:
我正在尝试根据一些测量数据创建直方图。数据格式如下,并保存在一个txt文件中(共约2000行):
17.05.2017 06:22:49;144;-1;550;-12
17.05.2017 06:23:19;143;-1;537;-13
我想将第 3 列 (550, 537 ...) 和 4 (-12,-13 ...) 中的数据写入直方图
# import
import sys
import re
import matplotlib.pyplot as plt
import numpy as np
# open file read
try:
d = open("result_CO2_1705a.txt")
except:
print("access not successfull")
sys.exit(0)
# create histogram
daten = d.read()
d.close()
zeilenliste = daten.split("\n")
print zeilenliste
laenge = len(zeilenliste
print laenge
i = 0
li_ppm = []
li_dppm = []
for zeile in zeilenliste:
if zeile:
zwliste = zeile.split(";")
# print zwliste
li_ppm.append(zwliste[3])
print li_ppm
print li_dppm
ppm_array = np.asarray(li_ppm)
print ppm_array
a = np.histogram(int(ppm_array), 10, laenge, False, None, None)
对于最后一行 a = 我收到错误消息:
only length-1 arrays can be converted to Python scalars
当我第一次使用 numpy 和直方图时,我很乐意收到有关此错误消息根本原因的反馈。
非常感谢你
丹尼尔
【问题讨论】:
标签: python arrays numpy matplotlib