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 8418483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:20:44+00:00 2026-06-10T02:20:44+00:00

import csv datafile = csv.reader(open(‘datafile.csv’,’rb’), delimiter=,, quotechar=’|’) date, data1, data2, data3 = [], [],

  • 0
import csv

datafile = csv.reader(open('datafile.csv','rb'), delimiter=",", quotechar='|')
date, data1, data2, data3 = [], [], [], []

for row in datafile:
    date.append(row[0])
    data1.append(row[1])
    data2.append(row[2])
    data3.append(row[3])

Here is what I want to do. As you can see, this code takes 1 csv file and creates 4 lists from it. Now I can and will do math on those lists, like data1[4]-data2[30]

But I also have a few other files that I also want to create lists from. But I want to be able to reuse my code like my math seen above ( data1[4]-data2[30] ). So ideally everything including the arrays should be named the same for the other files.

I am super new to programming so this is proving to be a bit difficult. Obviously things will clash with everything being named the same and I don’t want that. So somehow via oop I want to be able to re-use my math logic and not have to copy some massive math algorithms and renaming everything.

Obviously I don’t want to just do math on these 4 arrays, save the results and change file name. Nope everything has to work at the same time inside my program.

I’m hoping I can get some tips on how to do this. I’m trying to widen my scope of knowledge about how oop works but its proving to be difficult. I’m thinking getting an explanation on how to fix my own problem would be best.

So to recap, I have 4 lists created from 1 file. I want to create 4 additional lists from a different file but have the arrays be named the same. And then I only have to create my massive math calculations once and have it work for everything. And have it work for any future new data introduced into my program.

  • 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-10T02:20:46+00:00Added an answer on June 10, 2026 at 2:20 am

    You want a data container, you get this by making a class with an appropriate constructor (init method here). Below is an example where you load data from two files.

    import csv
    
    datafile1 = csv.reader(open('datafile1.csv','rb'), delimiter=",", quotechar='|')
    datafile2 = csv.reader(open('datafile2.csv','rb'), delimiter=",", quotechar='|')
    
    
    class data(object):
    
        def __init__(self,data_file):
    
            self.date, self.data1, self.data2, self.data3 = [], [], [], []
    
            for row in data_file:
                self.date.append(row[0])
                self.data1.append(row[1])
                self.data2.append(row[2])
                self.data3.append(row[3])
    
    
    data1 = data(datafile1)
    data2 = data(datafile2)
    

    If you want to apply methods (the math stuff you describe) you might want to put these methods in the class, can you give some more concrete examples of exactly what you want to do?

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

Sidebar

Related Questions

import csv sample row = 10/6/2010,73.42,74.43,72.9,74.15,2993500 filename_in = 'c:/python27/scripts/fiverows.csv' reader = csv.reader(open(filename_in, rb), dialect=excel,
import csv from geopy import geocoders g = geocoders.Google() spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t',
import csv with open('test.csv', 'w') as outfile: writer = csv.writer(outfile, delimiter=',', quoting=csv.QUOTE_MINIMAL) writer.writerow(['hi', 'dude'])
import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter =
import csv a=[] with open('large.csv','w') as f1: writer=csv.writer(f1, delimiter='\t',lineterminator='\n',) for i in range(1000000): for
In a basic I had the next process. import csv reader = csv.reader(open('huge_file.csv', 'rb'))
import csv from geopy import geocoders import time g = geocoders.GeocoderDotUS() spamReader = csv.reader(open('locations.csv',
import csv from geopy import geocoders import time g = geocoders.GeocoderDotUS() spamReader = csv.reader(open('locations.csv',
Possible Duplicate: Open a file in the proper encoding automatically my code: import csv
Im using the following in Python2.x ; import csv f = open('test.csv', 'wb') writer

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.