1

I have data containing some large arrays in a .csv like:

df = pd.DataFrame()

for x in range(1, 6):
    data = {'a':x,
            'b':np.array(range(1, 10000))}

    df = df.append(data, ignore_index=True)

df.to_csv(f"./src/temp/test.csv", index=True)

The array get saved like:

0 1 [   1    2    3 ... 9997 9998 9999]
1 2 [   1    2    3 ... 9997 9998 9999]
2 3 [   1    2    3 ... 9997 9998 9999]
3 4 [   1    2    3 ... 9997 9998 9999]
4 5 [   1    2    3 ... 9997 9998 9999]

Which makes it impossilbe to read them later. How can I solve this?

EDIT: I was planning to read it later like:

convert = lambda x: np.fromstring(x.strip('[]'), dtype=int, sep=' ')
df = pd.read_csv('./src/temp/test.csv',
                  converters={'b': convert},
                  index_col=0)
1
  • Who/what is the intended reader? Pickle it? Commented May 4, 2021 at 6:12

1 Answer 1

1

You can change the numpy printing threshold with set_printoptions():

threshold: Total number of array elements which trigger summarization rather than full repr (default 1000). To always use the full repr without summarization, pass sys.maxsize.

np.set_printoptions(threshold=100000) # or threshold=sys.maxsize
df.to_csv('./src/temp/test.csv', index=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.