Python Forum
Importing python data to Textfile or CSV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing python data to Textfile or CSV
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  textfile to customtkinter combobox janeik 6 1,723 Aug-31-2023, 02:50 AM
Last Post: deanhystad
  python standard way of importing library mg24 1 895 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  ssues with importing data from ODBC Slavek_d 1 1,401 Feb-01-2022, 09:57 AM
Last Post: ibreeden
  importing a list of numbers into python script barrypyth 8 4,542 Aug-22-2020, 09:10 PM
Last Post: barrypyth
  importing a CSV file into Python russoj5 1 2,945 Aug-02-2020, 12:03 AM
Last Post: scidam
  Importing data from a text file into an SQLite database with Python macieju1974 7 4,097 Jun-29-2020, 08:51 PM
Last Post: buran
  importing CSV file into a OOP Class table using Python faruk61 1 2,951 Apr-15-2020, 12:00 PM
Last Post: faruk61
  importing CSV file into a HTML table using Python trybakov 1 2,278 Feb-22-2020, 09:47 PM
Last Post: scidam
  Replace Line in Textfile Deadline 1 10,367 Nov-04-2019, 07:14 PM
Last Post: Larz60+
  Importing Custom Modules in Python 3 Flexico 1 2,577 Aug-24-2019, 08:11 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020