1
votes

I have array of numpy and I need to save it to csv file. I want to get nice display as in the picture below when I open it using notepad I want all the column to start at same position, like the [2,5] and [4] are I cant figure out how to set the dynamic padding between columns

Thanks alot Alon enter image description here

1
Use tab as a delimiter? You haven't given an upper bound on how long those arrays might be, so it's not easy to suggest a solution. - roganjosh
Smells alot like homework... Also, we have no idea what your data looks like, and you've made no attempt at beginning to solve this - Ofer Sadan
I have only 3 columns and I cant have any assumptions about their length. I tried to use tab as delimiter but It did not changed the space between the columns dynamicly - Alon Galpe

1 Answers

1
votes

you can use xlsx format for that using pandas library in python

import pandas as pd
import numpy as np

# Creating a dataframe and saving as test.csv in current directory
df = pd.DataFrame(np.random.randn(100000, 3), columns=list('ABC'))
df.to_csv('test.csv', index = False)

# Reading in test.csv and saving as test.xlsx

df_new = pd.read_csv('test.csv')
writer = pd.ExcelWriter('test.xlsx')
df_new.to_excel(writer, index = False)
writer.save()