How does python extract data from multiple specified samples?

the available data is as follows (the real situation is about hundreds of thousands of rows):

clipboard.png

for example, there is another file p.txt with a column as follows:
"8240004146789610
8240004356417597
...
8240004146757344 "
I need to extract the number in the fourth column p.txt from the data. Is there any fast method (the method is not limited to pandas)?
is actually a sampling process in which a specified sample is taken and the fourth list is the number in the specified file.

the idea now is to loop in p.txt, then use pandas to read the original data, and then extract the number of the fourth column = = loop. Is there a faster way?

May.20,2022

consider using pandas's apply, minus the steps of p.txt loop and subsequent matrix stitching.
that is, read the data in p.txt and convert it to a list such as P, then read the original data with pandas, and execute:

df[df[<>].apply(lambda x: x in P)]
Menu