Python Forum
Importing python data to Textfile or CSV - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Importing python data to Textfile or CSV (/thread-28749.html)



Importing python data to Textfile or CSV - yanDvator - Aug-02-2020

I need help storing an array in a text file that's being plotted using matplotlib.
t = np.linspace(0, sampling_time * 30, 31)
w = []
for a in range(Entropy):
        plt.plot(t, w[a], label='Entropy %s' % (a + 1)) 
I need to save the (t ,w[a]) in a textfile or csv file ?

I have tried
 np.savetxt('file_numpy.txt', t, w)
but its not working.

I tried

a_file = open("file.txt", "w")
    for row in w:
        np.savetxt(a_file, row)
a_file.close()
This is working to store the file sequentially but without the time axis and Theres no spacing for the next index.
How to include a space in between each index i.e for each row.
somewhat like this :
t | w
-----
1 100
2 80
3 70
4 60
5 203

6 534
7 124
8 5645
9 663
10 355