-3

guys, I am new in Python. I have a question. I have a text file, that contains various information. But I only want to extract a specific column start from specific row. In the follow data sheet, I only want to extract the "CYCLES/TIMES" column without title. Please help.

4) FOR MULTI-PROCESS EXECUTION, THE ESTIMATED VALUE OF FLOATING POINT OPERATIONS FOR EACH PROCESS
          IS BASED ON AN INITIAL SCHEDULING OF OPERATIONS AND MIGHT NOT REFLECT THE ACTUAL FLOATING 
          POINT OPERATIONS COMPLETED ON EACH PROCESS. OPERATIONS ARE DYNAMICALLY BALANCED DURING EXECUTION, 
          SO THE ACTUAL BALANCE OF OPERATIONS BETWEEN PROCESSES IS EXPECTED TO BE BETTER THAN THE ESTIMATE
          PRINTED HERE.
      (5) THE UPPER LIMIT OF MEMORY THAT CAN BE ALLOCATED BY ABAQUS WILL IN GENERAL DEPEND ON THE VALUE OF
          THE "MEMORY" PARAMETER AND THE AMOUNT OF PHYSICAL MEMORY AVAILABLE ON THE MACHINE. PLEASE SEE
          THE "ABAQUS ANALYSIS USER'S MANUAL" FOR MORE DETAILS. THE ACTUAL USAGE OF MEMORY AND OF DISK
          SPACE FOR SCRATCH DATA WILL DEPEND ON THIS UPPER LIMIT AS WELL AS THE MEMORY REQUIRED TO MINIMIZE
          I/O. IF THE MEMORY UPPER LIMIT IS GREATER THAN THE MEMORY REQUIRED TO MINIMIZE I/O, THEN THE ACTUAL
          MEMORY USAGE WILL BE CLOSE TO THE ESTIMATED "MEMORY TO MINIMIZE I/O" VALUE, AND THE SCRATCH DISK
          USAGE WILL BE CLOSE-TO-ZERO; OTHERWISE, THE ACTUAL MEMORY USED WILL BE CLOSE TO THE PREVIOUSLY
          MENTIONED MEMORY LIMIT, AND THE SCRATCH DISK USAGE WILL BE ROUGHLY PROPORTIONAL TO THE DIFFERENCE
          BETWEEN THE ESTIMATED "MEMORY TO MINIMIZE I/O" AND THE MEMORY UPPER LIMIT. HOWEVER ACCURATE
          ESTIMATE OF THE SCRATCH DISK SPACE IS NOT POSSIBLE.
      (6) USING "*RESTART, WRITE" CAN GENERATE A LARGE AMOUNT OF DATA WRITTEN IN THE WORK DIRECTORY.


                              E I G E N V A L U E    O U T P U T     

 MODE NO      EIGENVALUE              FREQUENCY                GENERALIZED MASS           COMPOSITE MODAL DAMPING
                             (RAD/TIME)   (CYCLES/TIME)     (TOTAL)  (ACOUSTIC FRACTION)


       1      1.13817E+05     337.37         53.694         1.0000        5.48556E-03     0.0000    
       2      1.48191E+05     384.96         61.268         1.0000        5.15017E-03     0.0000    
       3      1.77303E+05     421.07         67.016         1.0000        6.92114E-03     0.0000    
       4      2.43292E+05     493.25         78.503         1.0000        2.69776E-02     0.0000    
       5      2.62266E+05     512.12         81.506         1.0000        4.64713E-03     0.0000    
       6      3.61046E+05     600.87         95.632         1.0000        4.13076E-03     0.0000    
       7      3.96750E+05     629.88         100.25         1.0000        1.50593E-02     0.0000    
       8      4.06070E+05     637.24         101.42         1.0000        1.40587E-02     0.0000    
       9      5.71261E+05     755.82         120.29         1.0000        1.07618E-02     0.0000    
      10      5.90913E+05     768.71         122.34         1.0000        1.11108E-02     0.0000    
      11      6.36854E+05     798.03         127.01         1.0000        4.06691E-03     0.0000    
      12      7.60037E+05     871.80         138.75         1.0000        3.86252E-03     0.0000    
      13      7.70433E+05     877.74         139.70         1.0000        9.25278E-03     0.0000  

2 Answers2

4

What is the format of the file, is it a txt file?

You can utilize readline(), once you reach the lines that you want the lines in red you could strip based off spaces between the columns.

MODE NO        EIGENVALUE              FREQUENCY                GENERALIZED MASS           COMPOSITE MODAL DAMPING
                             (RAD/TIME)   (CYCLES/TIME)     (TOTAL)  (ACOUSTIC FRACTION)
1             1.13817E+05     337.37         53.694         1.0000        5.48556E-03           0.0000    
2             1.48191E+05     384.96         61.268         1.0000        5.15017E-03           0.0000    

The list of line 1 would be ['1', '1.13817E+05', '337.37', '53.694' , '1.0000', '5.48556E-03', '0.0000']

The elements you want will be @ position 3 of every list of each line, 0 being the first element.

mallocation
  • 526
  • 6
  • 13
1

There are several ways to read data from files in Python. A very useful library is named Pandas, it should most likely be installed alongside Python, if not you can type:

pip install pandas

If you eliminate the information not corresponding to your columns and then read the file by:

data = pd.read_csv('output_list.txt', sep=" ", header=None)
data.columns = ["Mode NO", "Eigenvalue", "Frequency", "etc."]

This answer is extracted from another Stack Overflow question in which they explain this and another techniques to extract information using Pandas.