Python Forum
How to put together datas from different files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to put together datas from different files
#1
Hello,

I am dealing with a program, which puts together some datas from different files. I wrote a part of the code it looks like:


for path, subdirs, files in os.walk(r'./'):
    for filename in files:
        if filename.startswith("mli_value_IHAR"):
            f = os.path.join(path, filename)
            date = (f[-12:-4])
            myfile = open('test.txt', 'a')
            myfile.write(date + "\n")
            myfile.close()

But I also wold like to insert a part to the code, which puts each row - so next to the dates - an intesity value, that would come from a file called mli_value_IHAR_date. This file looks contains a number, that I want to convert to a real number (405328.0):
2624 3127 4.05328e+05

So finally it would look like fowexample 20180101 405328.0.
Can anyone help me how to solve this problem?
Thanks
Reply
#2
mli_file = open("mli_value_IHAR_date", "r") 	
data = mli_file.readline().split(" ")

val = str(float(data[2]))

myfile.write(date + " " + val + "\n")
Reply
#3
And your next step in learning Python is formatting output https://pyformat.info/
Reply
#4
I have one more question. How can I skip to get an ,,ValueError: could not convert string to float:" if there is no data in the text file?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  time setup for realtime plotting of serial datas at high sampling rate alice93 6 3,723 Jan-07-2022, 05:41 PM
Last Post: deanhystad
  iterate and print json datas enigma619 1 1,917 Apr-01-2020, 11:48 AM
Last Post: buran
  Datas are not insert into database aravinth 1 2,187 Dec-21-2019, 04:17 PM
Last Post: buran
  How to put together datas into a file? Krszt 1 1,912 Nov-07-2018, 04:06 PM
Last Post: ichabod801
  Plotting datas Krszt 2 2,372 Oct-31-2018, 03:29 PM
Last Post: Davis4109
  How to write datas into a file? Krszt 2 2,383 Oct-25-2018, 01:45 PM
Last Post: Krszt
  how to retrieve datas with Overpass API python wrapper apollo 0 2,898 Oct-15-2017, 02:27 PM
Last Post: apollo

Forum Jump:

User Panel Messages

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