【发布时间】:2021-01-13 14:04:40
【问题描述】:
链接上方是一个名为“19031783_result.txt”的结果文件。每个 .txt 文件都包含统计结果,我想将其组织到数据库中。
所以我有数百个结果文件需要合并到一个数据库中。最后三列是每个 Bin 缺陷计数的限制,例如 Bin 1 限制为 10,Bin 2 限制为 5,Bin 3 限制为 3,Bin 4 限制为 0。所以完美意味着没有缺陷,好意味着它在规格范围内失败意味着它超出了限制。
我在 python 方面没有太多经验,我需要指导如何从 .txt 文件创建这个数据库。 Python 更好用,因为它可以处理大量数据,而且速度更快。
import os
import pandas as pd
from glob import glob
stock_files = sorted(glob('*result.txt'))
stock_files
df = pd.concat([pd.read_csv(file, sep="\t").assign(filename = file) for file in stock_files], ignore_index = True)
df = pd.DataFrame() #this is the bit I am stuck on
这是我当前的输出,我需要清理它并将其转换为我有 excel 电子表格屏幕截图的数据库(2:https://i.stack.imgur.com/SebTl.png)
Delaminated area fraction: 9.63722329310847E-06 filename \
0 Bin1 Defect count with diameter between 1 µm a... 19031781_result.txt
1 Bin2 Defect count with diameter between 76 µm ... 19031781_result.txt
2 Bin3 Defect count with diameter between 301 µm... 19031781_result.txt
3 Bin4 Defect count with diameter exceeding 1001... 19031781_result.txt
4 NaN 19031782_result.txt
5 NaN 19031782_result.txt
6 NaN 19031782_result.txt
7 NaN 19031782_result.txt
8 NaN 19031783_result.txt
9 NaN 19031783_result.txt
10 NaN 19031783_result.txt
11 NaN 19031783_result.txt
【问题讨论】:
-
据我所知,没有一个模块可以轻松完成此操作,因此最好分多个步骤完成此操作。你有任何现有的代码,你试图让它工作吗?
-
我添加了启动模块
标签: python python-3.x excel pandas dataframe