Home > Blockchain >  How to gather all the rows containing a same text into another dataframe
How to gather all the rows containing a same text into another dataframe

Time:10-26

I am trying to find [XXX] from one specific column 'e' and want to gather all the rows

this is test3.csv. https://wetransfer.com/downloads/8a87b284d2be1582c35e5a6a3f6e116620211025160531/fd05a6

The code I tried..

import pandas as pd
import numpy as np

df = pd.read_csv('test3.csv')
all = pd.DataFrame([df.iloc[i,j] for i,j in zip(np.where('[XXX]'))])
print(all)

CodePudding user response:

try it.

import pandas as pd
import numpy as np
d = {'col1': [1, 2,3,4,5,6,7,8,9], 'col2': [3, 4,5,6,7,8,9,10,11],'col3': [7, 8,9,10,11,12,13,14,15]}
df = pd.DataFrame(data=d)

print(df)

all = df[df.isin([3]).any(axis=1)]
print(all)
  • Related