Home > other >  Read TXT file to Excel in question?
Read TXT file to Excel in question?

Time:09-19

Beginners,
Python reads text files are stored to excel in the problem, just learning grammar, don't know whether this kind of situation need to read line by line, or how many, each read written at the fastest speed,
Please advise method, or give a simple code, thank you very much!!!!!!
C: \ TXT \ folder with multiple file (thousands, each a few K);
Multiple file types;
Need to read *. TXT file,
All are commas,
Step 1: read the first line (AD) fourth value is 33, on behalf of the total number of rows
The second step: read the third line VI ninth value is 06
Corresponding lines in the BC to find before 6, find,6,9,11,12 5 (12 of 20 e0478bjd1td_0001. Avi is only)
Then 12,5,6,9,11 of BC, AD 3rd, TI four VI. 4, the formation of a record in the excel,

VI BC the fourth of the corresponding relationship between the BC, the corresponding relationship between VI second is
(AD, TI, ED is a line)
File format:
The AD, BJD1, 03-24-2020 12:37:10, 33
TI, BJD1, 03-24-2020 12:37:10, 20 e0478bjd1. TXT, 24,6,0,48.44, 0,0,0,0,0,0, N
VI, 1, "6080 A, 0040481, A, R, and practices"
VI, 2, "A, B, 0040482, R, 4080,,"
VI, 3, "C., 0040483, A, R, 2080, 11"
VI, 4, "4080 C, 0040473, A, R,"
VI, 5, "A, B, 0040472, R, 4080,,"
VI, 6, "4080, A, 0040471, A, R,"
BC, TD, 1, 1, 1 R,,0,0,48.44, U, avi
2.3, 20 e0478bjd1td_0001.BC, TD, 2, 1, 2 R,,23,0,48.44, L, avi
0, 20 E0478BJD1TD_0002.BC, TD, 3, 1, R, 3102,0,48.44, U, avi
0, 20 E0478BJD1TD_0003.BC, TD, 4, 1, 4 R,,23,0,48.44, U, avi
0, 20 E0478BJD1TD_0004.BC, TD, 5, 1, 1 R,,46,0,48.44, U, avi
0, 20 E0478BJD1TD_0005.BC, TD, 6, 1 R, 2,23,0,48.44, U, avi
3.2, 20 e0478bjd1td_0006.BC, TD, 7, 2, R, 3103,0,48.44, U, avi
0, 20 E0478BJD1TD_0007.BC, TD, 8, 2, 4 R,,23,0,49.06, U, avi
4.4, 20 e0478bjd1td_0008.BC, TD, 9, 2, R, 1,46,0,49.06, U, avi
0, 20 E0478BJD1TD_0009.BC, TD, 10, 2, R, 2,23,0,49.06, U, avi
4.5, 20 e0478bjd1td_0010.BC, TD, 11, 3, R, 3103,0,49.06, U, avi
0, 20 E0478BJD1TD_0011.BC, TD, 12, 3, 4 R,,23,0,49.06, U, avi
0, 20 E0478BJD1TD_0012.BC, TD, 13, 4, 1 R,,46,0,49.68, U, avi
0, 20 E0478BJD1TD_0013.BC, TD, 14, 21, R, 2,23,0,49.68, U, avi
0, 20 E0478BJD1TD_0014.BC, TD, 15, 4 R, 3103,0,49.68, U, avi
0, 20 E0478BJD1TD_0015.BC, TD, 16, 21, R, 4,23,0,49.68, U, avi
0, 20 E0478BJD1TD_0016.BC, TD, 17, 5, R, 1,46,0,49.68, U, avi
0, 20 E0478BJD1TD_0017.BC, TD, 18, 5, 2 R,,23,0,49.68, U, avi
0, 20 E0478BJD1TD_0018.BC, TD, 19, 5, R, 3103,0,50.30, U, avi
0, 20 E0478BJD1TD_0019.BC, TD, 20, 5, 4 R,,23,0,50.30, U, avi
0, 20 E0478BJD1TD_0020.BC, TD, 21, 6, 1 R,,46,0,50.30, U, avi
0, 20 E0478BJD1TD_0021.BC, TD, 22, R, 2,23,0,50.30, U, avi
0, 20 E0478BJD1TD_0022.BC, TD, 23, 6, R, 3103,0,50.92, U, avi
0, 20 E0478BJD1TD_0023.BC, TD, 24, 6, 4 R,,23,0,50.92, U, avi
0, 20 E0478BJD1TD_0024.ED, BJD1, 03-24-2020 12:37:10, 33

The results of the first line of the TXT file to form line 24, temporarily separated with *,
20 e0478bjd1td_0001. Avi * R * 1 * 48.44 * 2.3 * 03-24-2020 12:37:10 * 20 e0478bjd1. TXT * 0040481

CodePudding user response:

Tell you a train of thought:
1. Readlines one-time read a file, each line will be split into a list
2. Each row in the enumerate add line number
3. The results of 2 into a dictionary
4. Deal with this dictionary

CodePudding user response:

Use readline read while processing the data, not specifications of the data with the pandas
  • Related