-1

I stored a calculated variable in another file let's say A.txt as follows:

123
1123
123
123
123
...

I want to use single variable each time from file A.txt (sequentially) when each acb.* read by pandas, processing acb.* multiples files that I was doing as follows using pandas: (how do I read acb.* file in numeric order like 1 then 2 and so on?)

  import pandas as pd
  import numpy as np
  import glob
  for filename in sorted(glob.glob('acb.*')): 
  with open(filename) as f:
    df = pd.read_table(f, sep=" ", skiprows=2)

How to combine this two task simultaneously? I know we can read two files at single time in pandas but how do I use single variable from file A.txt each time when I read a acb.* file sequentially?

Abhijeet
  • 1
  • 5

1 Answers1

0

not sure if i understood your question fully but you can read the data into pandas df, and then looping through each row while looping through each line of the abc file:

import pandas as pd
import numpy as np
import glob

df = pd.read_table(f, sep=" ", skiprows=2)

for filename in sorted(glob.glob('acb.*')): 
    with open(filename) as f:
       for row in df.itertuples():
       print(row.column1)
       print(row.Index)
       #do tasks 
Jessica
  • 2,923
  • 8
  • 25
  • 46