I have 2 txt files being read by Pandas.
The first file contains:
code speed1 speed2
VST 50/20M 15/1M
BMR 50/20M 15/1M
BMQ 50/20M 15/1M
VSK 50/20M 50/20M
The second file contains:
VST,L_602356450160818666
VSK, 602356450160818556
and so on
I would like to take e.g. VST in the second file and match the code in the first file and retrieve its corresponding speed 1 and 2 values. And do this for VSK etc.
I have begun by using by using index_col=0
in the first file and using df.loc[VST] to get the values. How do I put df.loc
into a for loop to iterate over 100's of codes in the second file. Or is there a better way?
Tks.
UPDATE:*************
Come up with this:
dataset = pd.read_csv('firstFile.csv', usecols=cols,
header=None, index_col=0)
df = pd.read_csv('secondFile.txt', header=None, index_col=0)
for i in df.iterrows():
for j in dataset.iterrows():
if i[0] == j[0]:
print(dataset.loc[j[0]])
Out:
20 50/20M
22 50/20M
Name: VST, dtype: object
20 50/20M
22 50/20M
Name: VSK, dtype: object
The output I would like is a dictionary/json form and use VST as the key and get the values. Should turn the two files into a json first before any other process?