I have a text file in the following format.
[1,2]
[3]
[4,5,6,7,10]
And I have a pandas DataFrame like following.
df = pd.DataFrame({'id' : [1,2,3,4,5,6,7],
'path' : ["p1,p2,p3,p4","p1,p2,p1","p1,p5,p5,p7","p1,p2,p3,p3","p1,p2","p1","p2,p3,p4"]})
output:
id path
0 1 p1,p2,p3,p4
1 2 p1,p2,p1
2 3 p1,p5,p5,p7
3 4 p1,p2,p3,p3
4 5 p1,p2
5 6 p1
6 7 p2,p3,p4
I want to slice the DataFrame based on the text file. What is the wrong with following? It produces empty DataFrames.
for line in lines:
print line
print df[df['id'].isin(line)]
But it works fine with following.
for line in lines:
print df[df['id'].isin([1,2])]