I coded how to load and save txt file using pandas in python.
import glob
filenames = sorted(glob.glob("D:/a/test*.txt"))
filenames = filenames[0:5]
import numpy as np
import pandas as pd
for f in filenames:
df = pd.read_csv(f, skiprows=[1,2,3], dtype=str, delim_whitespace=True)
df.to_csv(f'{f[:-4]}.csv', index=False)
------>There are 10 result files in a folder
- test1.txt, test2.txt, test3.txt, test4.txt, test5.txt,
test1.csv, test2.csv, test3.csv, test4.csv, test5.csv
#Result csv.file(test1.csv)
abc:,1.233e-03
1.234e-04,
1.235e-02,
1.236e-05,
1.237e-02,
1.238e-02,
But I have some problems as follows.
I don't know how to rename test1.txt, test2.txt, test3.txt, test4.txt, test5.txt into c1.csv, c2.csv, c3.csv, c4.csv, c5.csv.
I want remove 'abc:,'data in all test(1,2,3,4,5).csv files, but I don't know how to delete and replace data.
Do you know how to rename(change) file name and remove data (specific character) referred to above problems in python?
origin data
test1.txt (it is similar to other file-{test2,test3,test4, test5}.txt)
abc: 1.233e-03
def: 1.64305155216978164e+02
ghi: 4831
jkl:
1.234e-04
1.235e-02
1.236e-05
1.237e-02
1.238e-02
Expected result
(it must chage test1,2,3,4,5.txt files into c1,2,3,4,5.csv files, it only remove herder name(abc:), also def:,ghi:,jkl: rows should remove.)
1.233e-03
1.234e-04
1.235e-02
1.236e-05
1.237e-02
1.238e-02