when asking a python/pandas question on stackoverflow I often like to provide a sample dataframe. I usually have a local csv file I deal with for testing.
So for a DataFrame I like to provide a code in my question like
df = pd.DataFrame()
Is there an easy way or tool to get a csv file into code in a format like this, so another user can easily recreate the dataframe?
For now I usually do it manually, which is annoying and time consuming. I have to copy/paste the data from excel to stackoverflow, remove tabs/spaces, rearrange numbers to get a list or dictionary and so on.
Example csv file:
col1 | col2 |
---|---|
1 | 3 |
2 | 4 |
I if want to provide this table I can provide code like:
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
I will have to create the dictionary and Dataframe manually. I manually have to write the code into the stackoverflow editor. For a more complex table this could lead to a lot of work.
Hope you get the "problem".