Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:52:46+00:00 2026-06-02T05:52:46+00:00

I am trying to figure out a better way to extract data from a

  • 0

I am trying to figure out a better way to extract data from a large number of files, run additional calculations on some data, and finally format it into a something readable by a spreadsheet application. Below is how I am currently doing this but I am convinced there must be an easier way.

First I create a definition that will search the files and extract the data. I use a definition since sometimes the data will be compiled from several locations. I am doing this via a mixture of regular expressions and find all. This can be formatted differently if needed. The result of this is something like:

RawData=
[[M1,A1,305.91,288.12,Variable_M1_A1],
[M1,A2,319.07,303.70,Variable_M1_A2],
[M2,A1,237437.32,191460.91,Variable_M2_A1],
[M2,A2,270773.28,192581.05,Variable_M2_A2]]

What I wish to do with some of the data is organize it in such a way that a grid is created from the variables A and M and then the data from a column is placed in the correct grid location. Realistically looks like a simple two dimension matrix with the first row and first column indicating the variables.

What the csv file should look like:

Placeholder,A1,A2
M1,Variable_M1_A1,Variable_M1_A2
M2,Variable_M2_A1,Variable_M2_A2

What I currently am doing is creating an empty matrix (3×3 in this case) calling it Result then running the following code. The basically iterates over all lines and all variables when the variables match, it assigns the Result matrix a value from the RawData.

MVar=[M1,M2]
AVar=[A1,A2]
for a in range(len(RawData):
    for b in range(len(MVar)):
        for c in range(len(AVar)):
            if RawData[a][0]==Mvar[b] and RawData[a][1]==AVar[c]:
                Result[b+1][c+1]=RawData[a][4]

I wrote a chunk of code that will take the RawData matrix and create the Result matrix based off all possible combinations of M1 and A1. If I want to outport this to .csv I simply use csv.writer. So this works great if I just want to organize the data that is already there. However when I want to do calculations with the data- such as generating another column that is based off values in the RawData that did not end up in the matrix- it becomes difficult. For example to take what the csv file output could look like:

Placeholder,A1,A2,NewA
M1,Variable_M1_A1,Variable_M1_A2,(RawData[0][3]*RawData[1][2]) 
M2,Variable_M2_A1,Variable_M2_A2,(RawData[2][3]*RawData[3][2])

Notice that the data for the calculations require the same M value but different A values. While this can be done it quickly becomes very convoluted.

Is there a simpler way to do this?

Edit:
Auto generation of the M and A list using:

 [MethodList[i] for i,x in enumerate(MethodList) if x not in MethodList[i+1:]]

This seems makes it easier to work with, however its still a convolute process!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:52:48+00:00Added an answer on June 2, 2026 at 5:52 am

    This was completed with the for loops and corresponding if conditions. I am still convinced there is a better way but this is entirely possible to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the best way to setup some tables in my
I've been trying to figure out the best way to return an order from
I am trying to figure out the best way to model a spreadsheet (from
I'm trying to figure out the best way to send post data to a
I'm trying to figure out a way to count the number of characters in
Trying to figure out the best way to set up collection lists for users
Trying to figure out the best way to do this: Should I do something
I'm trying to figure out the best way to manage multiple forms in a
I'm trying to figure out the best way to deal with writing multiple GUI
I'm trying to figure out the best way to approach this. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.