简体   繁体   English

从csv文件中读取特定值

[英]Reading a particular value from a csv file

I need to read a particular value from a csv file. 我需要从csv文件中读取特定值。 The sample below is the first three line of my input csv file. 下面的示例是我输入的csv文件的前三行。 I need to read the value 60 and save it in a variable.This value can change with every other input csv file. 我需要读取值60并将其保存在变量中。此值可以随每个其他输入csv文件而更改。

Start Time: 2/21/19 3:50 PM
RDT Sample Rate: 60
"PLEASE NOTE: The sample rate is read...

You don't need pandas for that, a simple function will do the trick : 你不需要pandas,一个简单的函数可以解决这个问题:

def find_num(path):
    f = open(path)
    f.readline()
    return int(f.readline()[:-1].replace('RDT Sample Rate: ', ''))

Is this the csv file itself? 这是csv文件本身吗? If so it looks like bad format. 如果是这样,它看起来像格式不好。 I would try 我会尝试

Start Time, RDT Sample Rate,

"2/21/19 3:50 PM", "60",

and then you should be able to reference what you need to. 然后你应该能够引用你需要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM