python批量读取txt

  txts = glob.glob(r'xxx\*.txt')
    data = np.empty([0, 14])
    for txt in txts:
        print(txt)
        temp_data = np.loadtxt(txt, delimiter=',', skiprows=1, usecols=range(2, 16), encoding='utf-8')
        temp = temp_data[temp_data[:, 0] < 70000, :]  # Filter area weather stations
        data = np.vstack([data, temp])
    np.save(r'xxx\data.npy', data)

你可能感兴趣的:(笔记,python,numpy,机器学习)