So I have tried this and got all the files (25 scribes files) combine into one. Each scribe contains 3330 ID number and there is an co ordinate X and Y to highlight the number of defects (STATUE) for each ID number. I want to know the total sum of STATUE for each ID number from all the files combined.
import os
import pandas as pd
from glob import glob
stock_files = sorted(glob('*AVI.als'))
dfList = []
stock_files
df = pd.concat((pd.read_csv(file).assign(filename = file) for file in stock_files), ignore_index = True)
X\tY\tSTATUS filename
0 14\t1\t0 2008-09728-AVI.als
1 15\t1\t0 2008-09728-AVI.als
2 16\t1\t0 2008-09728-AVI.als
3 17\t1\t0 2008-09728-AVI.als
4 18\t1\t0 2008-09728-AVI.als
... ... ...
83245 30\t90\t0 2008-13754-AVI.als
83246 31\t90\t0 2008-13754-AVI.als
83247 32\t90\t0 2008-13754-AVI.als
83248 33\t90\t0 2008-13754-AVI.als
83249 34\t90\t0 2008-13754-AVI.als
for all CSV files combine into one.txt file, I should see the result like this below
X Y STATUS
0 14 1 0
1 15 1 0
2 16 1 0
3 17 1 0
4 18 1 0
...
3330
Any help is much appreciated
I think you simply need to add the separator (sep=r"\t"):
df = pd.concat([pd.read_csv(file, sep=r"\t").assign(filename = file) for file in stock_files], ignore_index = True)
You can simply save to.txt like this:
df.to_csv("output.txt")
If you want the sum of STATUS for each ID (X) you can do this:
df.groupby(["X"])["STATUS"].sum()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.