-35

Often I have data science related questions. But in order to give reproducible examples I need to give a viewer data which leaves me with two options:

  1. I can write a script to randomly generate data, which distracts from the question itself and is time-consuming.
  2. The other option is simply printing some of my data off and adding "," between values so people can have a makeshift CSV file to work with.

It would be nice to simply upload small CSV files to supply sample data which is relevant to a question. There could be a reasonable limit implemented to the size of the files, for example a 10x10 limit would be easy for the site to manage.

In the comments I suggested Stack Overflow could dump the data after a certain time or if the question was answered, one commenter inferred that this meant the data was not important in the first place. If your question concerns a data visualization function, the visual answer of the question would still be valuable after the fact.

I am not the first person to encounter this issue even if I'm not the best at making the case for this to be a feature. Please also consider the first question here:

  1. What is the best way to provide necessary data that cannot be provided via the Minimal, Complete, and Verifiable example? ,
  2. How can a questioner post Excel data?
  3. CSV attachment for a Stack Overflow post
28
  • 15
    Why not simply put the data in the question if it's that small? Why does it need to be uploaded?
    – VLAZ
    Sep 15, 2022 at 5:47
  • It's not that simple, as I explained that involves printing the data out then adding a comma to each individual entry. I guess you could write a string manipulation script. 10x10 was not a hard limit I assumed there would be hosting issues so it was not meant to be an exact number, just indicating a small limit. Sep 15, 2022 at 5:50
  • 10
    "that involves printing the data out then adding a comma to each individual entry" yes, which gives you a CSV data. My question is why does this need to be a file which is uploaded, as opposed to taking that same data and putting just the text as part of the question?
    – VLAZ
    Sep 15, 2022 at 5:52
  • 14
    Which...you need to do in order to get a CSV file and you're suggesting uploading of CSV files. Thus at this point you already have the CSV data. Why does uploading make more sense when you already have it and you can copy/paste it in the question?
    – VLAZ
    Sep 15, 2022 at 5:54
  • 8
    If you already have CSV file, why not copy the 1st 5 lines of the file onto the question, as-is. Then format into a code-block. I'm confused with the "printing some of my data off and adding "," between values" If you truly have CSV data then you don't need to add any commas? Sep 15, 2022 at 5:54
  • 11
    "At this point printing sufficient data points and then formatting it is actually not simple." then the FR doesn't make sense on a different level - how would uploading a CSV help at all, since you need to convert that matrix into a CSV anyway. Your proposal is to allow supplying CSV data but also you're saying it's hard to provide CSV data. What am I missing? Why does uploading change anything here?
    – VLAZ
    Sep 15, 2022 at 5:59
  • 1
    "What happens if its 100x100?" is that really minimal reproducible example, in that case?
    – VLAZ
    Sep 15, 2022 at 6:03
  • 12
    "I don't see why stack can host image files" it doesn't. They are hosted by Imgur
    – VLAZ
    Sep 15, 2022 at 6:05
  • 9
    Also, your question about 100x100 data does come in conflict with your FR which suggests 10x10 as the limit. That's the very reason I asked why not include it in the question if it's that small. And your response was that it might be bigger? Can you please clarify what you're asking for here because I was basing my discussion in comments to the text in the question. Yet you seem to retort with information that's neither in the question, nor something I can reasonably guess.
    – VLAZ
    Sep 15, 2022 at 6:07
  • 16
    "Can be discarded after the questuion is answered as well." - This is a terrible idea and you are suggesting absolutely abusing Stack Overflow!!! This is not a help desk. If the dataset is discarded and it's crucial for the question, then the question loses value for future visitors. The whole point of asking a question is to help future visitors. If the dataset is discarded and the question still has value, then the dataset wasn't crucial.
    – VLAZ
    Sep 15, 2022 at 6:09
  • 2
    This question still makes no sense. If you have already made the csv, why can't you just copy a portion of the data from it? Sep 15, 2022 at 6:26
  • 2
    @AngusCampbell "there are functions in python and R that write csv's" yes so you can just copy the CSV and put it in your question... You could even come up with a small script of your own that nicely formats it as a markdown table. Sep 15, 2022 at 6:28
  • 5
  • 6
    A bunch of argumentative comments questioning people's knowledge, experience, motivations, etc. have been removed. Please stick to the merits of the feature request and not the people discussing it.
    – Ryan M Mod
    Sep 15, 2022 at 7:31
  • 6
    In case it isn't clear: "go to R right now and print a csv you will not get commas inbetween each data entry" - if you are printing a CSV in your R environment, that implies that you have a CSV file. What you do from here is to open the CSV file in an ordinary text editor. You will notice that it already contains the necessary commas etc., because that's what "CSV file" means. Copy and paste text from the text editor into the question, and apply whatever appropriate formatting. Sep 15, 2022 at 11:35

2 Answers 2

0

Here is an example in Python of generating some CSV data directly in the terminal window, which can then be copied and pasted without having to look for a separate file on your hard drive:

>>> import numpy as np
>>> data = np.eye(10) # for example
>>> # "Save" to an in-memory "file"
>>> import io
>>> text = io.StringIO()
>>> np.savetxt(text, np.eye(10), delimiter=',', fmt='%d')
>>> # and then view it:
>>> print(text.getvalue())
1,0,0,0,0,0,0,0,0,0
0,1,0,0,0,0,0,0,0,0
0,0,1,0,0,0,0,0,0,0
0,0,0,1,0,0,0,0,0,0
0,0,0,0,1,0,0,0,0,0
0,0,0,0,0,1,0,0,0,0
0,0,0,0,0,0,1,0,0,0
0,0,0,0,0,0,0,1,0,0
0,0,0,0,0,0,0,0,1,0
0,0,0,0,0,0,0,0,0,1

I still just think this looks really ugly and is distracting from the question itself.

We can use Markdown to format the data as a table:

| a | b | c |
|---|---|---|
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |

produces

a b c
1 0 0
0 1 0
0 0 1

Generating this programmatically is left as an exercise. Unfortunately a header row is required, which makes it not great for Numpy data.

If you are trying to create a MRE, better to write code that produces the desired input, even if it's ugly:

import IO
import numpy as np

fake_csv = (
    '1,0,0,0,0,0,0,0,0,0\n0,1,0,0,0,0,0,0,0,0\n'
    '0,0,1,0,0,0,0,0,0,0\n0,0,0,1,0,0,0,0,0,0\n'
    '0,0,0,0,1,0,0,0,0,0\n0,0,0,0,0,1,0,0,0,0\n'
    '0,0,0,0,0,0,1,0,0,0\n0,0,0,0,0,0,0,1,0,0\n'
    '0,0,0,0,0,0,0,0,1,0\n0,0,0,0,0,0,0,0,0,1\n'
)

with IO.StringIO(fake_csv) as data:
    my_array = np.loadtxt(fake_csv, delimiter=',')

# proceed with the rest of the example
0
14

It's not needed to upload a CSV file. You can generate the CSV file from R or Python or whichever your programming environment is. Open the CSV file in a text editor, and copy and paste it into your question. Example in R:

> data(mtcars)
> head(mtcars,10)
                   mpg cyl  disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
Duster 360        14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
Merc 240D         24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
Merc 230          22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
Merc 280          19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
> write.csv(head(mtcars,10),"cars.csv")

This generates cars.csv with the following contents:

"","mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"
"Mazda RX4",21,6,160,110,3.9,2.62,16.46,0,1,4,4
"Mazda RX4 Wag",21,6,160,110,3.9,2.875,17.02,0,1,4,4
"Datsun 710",22.8,4,108,93,3.85,2.32,18.61,1,1,4,1
"Hornet 4 Drive",21.4,6,258,110,3.08,3.215,19.44,1,0,3,1
"Hornet Sportabout",18.7,8,360,175,3.15,3.44,17.02,0,0,3,2
"Valiant",18.1,6,225,105,2.76,3.46,20.22,1,0,3,1
"Duster 360",14.3,8,360,245,3.21,3.57,15.84,0,0,3,4
"Merc 240D",24.4,4,146.7,62,3.69,3.19,20,1,0,4,2
"Merc 230",22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2
"Merc 280",19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4

As you can see, it has commas.

5
  • I still just think this looks really ugly and is distracting from the question itself. And again I feel like there would be situations this would be useful in. I'm gonna let this questions sit here and get upvoted or downvoted and see if people agree with me. Sep 15, 2022 at 6:35
  • 3
    @AngusCampbell I agree with you that such a block of data can be distracting in the sense of not being needed to understand a question. However, many times reading and understanding the data is important for answering the question, so it is useful to be able to see the data within the body of the question. If the block gets longer then it automatically gets a scroll bar so it will never be a huge block taking up all of the screen.
    – Marijn
    Sep 15, 2022 at 6:42
  • 3
    Another advantage is that it is more safe: you can see which data you are going to copy to your own computer, instead of trusting that a csv file download contains the data for the question and nothing else.
    – Marijn
    Sep 15, 2022 at 6:43
  • That's a very good point. Hadn't considered that. Sep 15, 2022 at 6:44
  • 9
    This seems like a totally fine solution to me, as someone who answers questions on the R tag I would be perfectly happy if someone shared the data this way. I wouldn’t be happy clicking on file download links on my work computer when I have no idea what they might contain.
    – user438383
    Sep 15, 2022 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .