-1

I have a .txt file (it is the header file of a 3D seismic file) with 90035 lines and 19 columns. Every column represents a different variable (header of the seismic file) and most of them are set to 0. I want to fill the 4th and the 18th columns: - the 4th column should be filled with values from 1 to 8185 and again from 1 to 8185 and again repetitevely for 11 times (8185x11=total numbers of lines) - the 18th column should have values increasing from 1 to 11 every 8185 lines, so that you got 8185 times each value from 1 to 11. Can you help me? I'm getting crazy with loops

Thanks a lot

here you can find the .txt file:

http://www.filehosting.org/file/details/728701/info.txt

Giulia
  • 5
  • 4

1 Answers1

0

The comments here are correct in that you should post some sample code to show the work that you've done.

You can see that it's kind of annoying to try to manipulate a particular column of a csv. A better solution might be to import the whole file into python and manipulate it in memory. Here we'll use pandas to manipulate the whole text file as a dataframe:

import pandas as pd
df = pd.read_csv('my_file.txt')
df['interesting_columnname'] = [x % 8184 for x in range(0, df.shape[0])]
df.to_csv('new_file.txt')
Seth Rothschild
  • 384
  • 1
  • 14