1

I have written below code and at the end I want to append two array in a single buffer. I want to save to text file. Here is my code :

t=0
while(t>=0 and t<len(nav_time)):
  if nav_time[t]>70000 and nav_time[t]<86400:
      one_time=nav_time[t]
     # print one_time
  if nav_time[t]>=0 and nav_time[t]<70000:
      sec_time=nav_time[t]+86400
      #print sec_time
  total_time=np.append(one_time,sec_time)  # only stores two values not all values
  t=t+1

example data

    Nav_time
   86399
86399.20313
86399.40625
86399.60156
86399.80469
0.003574
0.203574
0.403574
0.603574
0.803574
1.003575
1.203575
5
  • 2
    NumPy and append seldom go in the same sentence. Why not extend a list and create an array at the very end? Commented Mar 9, 2018 at 2:52
  • @cᴏʟᴅsᴘᴇᴇᴅ .Would you tell me the step. How to proceed Commented Mar 9, 2018 at 3:13
  • Can you provide a minimal reproducible example with expected output? Commented Mar 9, 2018 at 3:17
  • @cᴏʟᴅsᴘᴇᴇᴅ .Actually unable to upload data. Commented Mar 9, 2018 at 3:20
  • I don't want your data, I want an example. Please make up something? Commented Mar 9, 2018 at 3:21

2 Answers 2

1

You can create 2 lists for one_time and sec_time and append them after your for loop.
Here is a sample

t=0
# Create one_time and sec_time as list 
one_time = []
sec_time = []
while(t>=0 and t<len(nav_time)):
  if nav_time[t]>70000 and nav_time[t]<84600:
      one_time.append(nav_time[t])
     # print one_time
  if nav_time[t]>=0 and nav_time[t]<70000:
      sec_time.append(nav_time[t]+86400)
      #print sec_time
  #total_time=np.append(one_time,sec_time)  # only stores two values not all values
  t=t+1

# Concatenating the 2 lists, this will append sec_time after one_time in a single row.
total_time = np.concatenate((one_time, sec_time), 0)

# Saving to fileName.txt. This creates file with 1 column with multiple rows.
np.savetxt('fileName.txt', total_time, fmt='%f')

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your dataframe is named nav_time with a column named Nav_time, this will filter your values.

filter1 = nav_time.where(~(nav_time.Nav_time > 84600)).dropna()
filter2 = np.where(filter1 > 70000,filter1,filter1+86400)

np.savetxt('file.txt', filter2)

1 Comment

@ DJK. In this process I am missing some data

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.