python numpy读取数据_如何在python中使用numpy或pandas只读取两行之间的数据?

我有这样一个数据文件:# column 1 is the angle of incidence (degrees)

# column 2 is the wavelength (microns)

# column 3 is the transmission probability

# column 4 is the reflection probability

14.2000 0.300000 0.01 0.999920

14.2000 0.301000 0.02 0.999960

14.2000 0.302000 0.03 0.999980

14.2000 0.303000 0.04 0.999980

14.2000 0.304000 0.06 0.999980

14.2000 0.305000 0.08 0.999970

14.2000 0.306000 0.2 0.999950

14.2000 0.307000 0.4 0.999910

14.2000 0.308000 0.8 0.999860

14.2000 0.309000 0.9 0.999960

14.2000 0.310000 0.8 0.999990

14.2000 0.311000 0.4 0.999980

14.2000 0.312000 0.2 0.999960

14.2000 0.313000 0.06 0.999940

14.2000 0.314000 0.03 0.999930

14.2000 0.315000 0.02 1.00000

14.2000 0.316000 0.01 1.00000

所需的输出文件output.csv是:

^{pr2}$

我们怎样才能在Python熊猫或纽比中做到这一点呢?在

我的初步尝试是:#!/usr/bin/env python

# -*- coding: utf-8 -*-

# Author : Bhishan Poudel

# Date : June 16, 2016

# Imports

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

#==============================================================================

# read in a file

infile = 'filter_2.txt'

colnames = ['angle', 'wave','trans', 'refl']

print('{} {} {} {}'.format('\nreading file : ', infile, '','' ))

df = pd.read_csv(infile,sep='\s+', header = None,skiprows = 0,

comment='#',names=colnames,usecols=(0,1,2,3))

print(df)

# find value of wavelength just above 0.05

print("\n")

df = df[(df['trans'] >= 0.05) ]

print(df)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值