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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:19:15+00:00 2026-06-08T18:19:15+00:00

Say I have got some data series generated by my plotting application, and I

  • 0

Say I have got some data series generated by my plotting application, and I want to store them and recall them in .csv at will.

Each data set has four characteristics. A name, a set of x values (xvals), a set of y values (yvals) and a parent.

I’m currently imagining a .csv file the kind that I would generate in Excel, and I’m thinking:

name, DataSet1
xvals, 1,2,3,4,5
yvals, 1,4,9,16,25
parent, None
<linebreak>
name, DataSet2
xvals, 1,2,3,4,5
yvals, 21,23,24,25,26
parent, None
<linebreak>

and so on. It doesn’t feel very natural, and the implementation is looking kind of ugly. Does anyone have any suggestions?

In my application, each DataSeries instance already contains all the data I need. If I could actuallly save the instance object itself (or a collection of them) that would work just as well for the meantime (although I eventually want to be able to export the data for usage in Excel)

I want to tell python:

  1. read all the lines in the file. every time you read a “blank” line, insert a separator. consider each clump of lines a data set.

  2. read the first item in each line of the package. this is the type of information the rest of the cells in the row contain. take that referral, and put the data in all the adjacent cells, as a list, into the corresponding object attribute.

I have a way to make this happen, but it involves a lot of awkward specific calls to characters and positions which reminds me of the “GOTO” statement. I want something more organic and Pythonic.

Current approach:

class DataSet(object):
    def __init__(self, name, xvals, yvals, parent=None):
        self.name = name
        self.xvals = xvals
        self.yvals = yvals
        self.parent = parent

loaded_data = csv.reader(open('csv_data.csv', 'r'), delimiter=',')

container = []
dict = {}
for row in loaded_data:
    if list(row)[0] == '':
        container.append(dict)
        dict = {}
    else:
        dict[list(row)[0]] = filter(None,list(row)[1:])
container.append(dict)
  • 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-08T18:19:16+00:00Added an answer on June 8, 2026 at 6:19 pm

    Make data set and parent into columns, so your data looks like this:

    "Dataset","Parent","XVal","YVal"
    DataSet1,None,1,1
    DataSet1,None,2,4
    ...
    DataSet2,None,1,21
    DataSet2,None,2,23
    

    In general to make your data into a tabular format (like CSV), you need to restructure it as rows. If you have information that is associated not with a row but with some group of rows (e.g., the “data set name”), you should recast this is a column whose value is duplicated through the relevant rows. When you read in the data, you can easily filter on this column to get the relevant groups back.

    Incidentally, you might want to look at pandas, a library that provides useful tools for dealing with tabular data (including reading and writing CSVs and grouping on column values in the way I described).

    Edit: Based on your comments, it appears you’re not asking how to use CSV to store your data. You’re asking how to parse your ad hoc format. The answer to that is “write a parser yourself”; you could have a look at pyparsing. CSV libraries won’t parse it for you, because your format isn’t really CSV. Spreadsheets won’t work well with your format because it’s not tabular. If you want to use premade tools to handle your data, you need to change your data to use a preexisting format. This will lead to easier processing in the long run, and changing your data into the right format isn’t that difficult.

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

Sidebar

Related Questions

I've got some financial data to store and manipulate. Let's say I have 2
Say if've got a set of items with some data on them like this:
I have got the array containing some data, say, a header and a real
I've got a grid view. I want it to say you have nothing to
My application is written in C. I have a module that uses some data
I am trying to generate some test data. Say I have 1000 appointments that
In one file called say 'data' I have some tuples: tuple1 = (1, 2,
I have some data Foo that I want to pass from the browser to
This question about Timers for windows services got me thinking: Say I have (and
I've been thrown a project which I have to say I've not got the

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.