简体   繁体   English

从文件夹导入文本文件

[英]Importing text files from folders

I am using Python 3.7.我正在使用 Python 3.7。 I have hundreds text files containing stock price data in a parent folder.我在父文件夹中有数百个包含股票价格数据的文本文件。 I want extract only the closing price column of each text file.我只想提取每个文本文件的收盘价列。 Is there a way to extract only one column of each text file from the parent folder?有没有办法从父文件夹中只提取每个文本文件的一列?

I'm guessing you want to extract a specific line from a text file?我猜你想从文本文件中提取特定的行? If so then here's your answer.如果是这样,那么这就是你的答案。

File = open('File_Name.txt')
Lines = File.readlines()
print(Lines[Choose])

Choose means what ever line you want to print out.选择意味着您要打印的任何一行。 FYI 0 is the starting line so if you replace "Choose" with 0 you will print the first line written inside that text file.仅供参考 0 是起始行,因此如果您将“选择”替换为 0,您将打印该文本文件中写入的第一行。

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

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