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

  • Home
  • SEARCH
  • 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 3989274
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:21:11+00:00 2026-05-20T06:21:11+00:00

I have 500 CSV files in this format: IndicatorA_Name.csv 1900 1901 1902 … Norway

  • 0

I have 500 CSV files in this format:

IndicatorA_Name.csv

        1900    1901    1902 ...
Norway  3      2       
Sweden  1      3       3
Denmark 5      2       3    
... 

IndicatorB_Name.csv

        1900    1901    1902 ...
Norway  1      3       4
Sweden  1      2       
Iceland 1      6       3    
... 
  • Years in columns, countries in rows.
  • Notice that countries, years and values may differ between files.

I’d like to run through all these files and make a flat table (CSV file) with this structure:

country, year, IndicatorA_Name, IndicatorB_Name, ...
Sweden, 1900, 1, 1
Sweden, 1901, 3, 2
Norway, 1900, 3, 1
...

Preferably in PHP or JavaScript but I’m willing to learn something new.

  • 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-05-20T06:21:11+00:00Added an answer on May 20, 2026 at 6:21 am

    You should probably code something like following code:

        $file = file_get_contents('file.csv');
        $lines = explode("\n", $file); //lines
        $years = explode(";", $lines[0]); //first line is years, so it gives us array of years
        for($i = 1, $c = count($lines)-1; $i < $c; ++$i){ //iterate over lines (excluding years)
            $lineData = explode(';', $lines[$i]); //array from line
            $country = $lineData[0]; //first line entry is country
            unset($lineData[0]); 
            $indicators = $lineData; //and the rest are indicators
            query('INSERT INTO data(country, year, IndicatorA_Name) VALUES(?,?,?)', $country, $year, $indicators[0]);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of csv files (around 250), each having 300 to 500
I have this table: id feed_id ... Let's say that I have 500 rows
I have a directory with 500,000 files in it. I would like to access
i have this code: import csv import collections def do_work(): (data,counter)=get_file('thefile.csv') b=samples_subset1(data, counter,'/pythonwork/samples_subset3.csv',500) return
I have this code which export data from GridView to csv. It works with
I'm parsing a large csv files - about 500 meg (many rows, many columns).
I have a csv file of the format: 270291014011 ED HARDY - TRUE TO
I have 500,000 values for a variable derived from financial markets. Specifically, this variable
Suppose I have 500 jar files linked to my program totaling over 500 MB
I have a csv file and when i use this command SOLK<-read.table('Book1.csv',header=TRUE,sep=';') I get

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.