python读取csv文件指定数据_在Python中从CSV文件的特定列中提取数据

. . . and storing it in a PY file to use the data to graph after storing all the data in different files . . .

. . . I would want to store only "2345678@abcdef" and "365" in the new python file . . .

确实要将数据存储在python文件中吗?Python文件应该保存Python代码,它们应该可以由Python解释器执行。最好将数据存储在数据类型文件中(比如,preprocessed_data.csv)。在

要获得与模式匹配的文件列表,可以使用python内置的^{} library。在

下面是一个如何读取目录中的多个csv文件并从每个文件中提取所需列的示例:import glob

# indices of columns you want to preserve

desired_columns = [1, 4]

# change this to the directory that holds your data files

csv_directory = '/path/to/csv/files/*.csv'

# iterate over files holding data

extracted_data = []

for file_name in glob.glob(csv_directory):

with open(file_name, 'r') as data_file:

while True:

line = data_file.readline()

# stop at the end of the file

你可能感兴趣的:(python读取csv文件指定数据_在Python中从CSV文件的特定列中提取数据)