li>
      <li>Временной таргетинг</li>
      <li>Интеграция с Яндекс.Касса</li>
    </ul>
    <a href="#">Посмотреть</a>
  </figcaption>
</figure>

 Q:

How to count rows efficiently with one pass over the dataframe

I have a dataframe made of strings like this:
ID_0 ID_1
 g    k
 a    h
 c    i
 j    e
 d    i
 i    h
 b    b
 d    d
 i    a
 d    h

For each pair of strings I can count how many rows have either string in them  as follows.
import pandas as pd
import itertools

df = pd.read_csv("test.csv", header=None, prefix="ID_", usecols = [0,1])

alphabet_1 = set(df['ID_0'])
alphabet_2 = set(df['ID_1'])
# This just makes a set of all the strings in the dataframe.
alphabet = alphabet_1 | alphabet_2
#This iterates over all pairs and counts how many rows have either in either column
for (x,y) in itertools.combinations(alphabet, 2):
    print x, y, len(df.loc[df['ID_0'].isin([x,y]) | df['ID_1'].isin([x,y])])

This  gives:
a c 3
a b 3
a e 3
a d 5
a g 3
a i 5
a h 4
a k 3
a j 3
c b 2
c e 2
c d 4
[...]

The problem is that my dataframe is very large and the alphabet is of size 200 and this method does an independent traversal over the whole dataframe for each pair of letters.  
Is it possible to get the same output by doing a single pass over the dataframe somehow?

Timings
I created some data with:
import numpy as np
import pandas as pd
from string import ascii_lowercase
n = 10**4
data = np.random.choice
li > 
       < li > Временной таргетинг</li > 
       < li > Интеграция с Яндекс. Касса</li > 
     < /ul > 
     < a href="#">Посмотреть</a > 
   < /figcaption > 
 < /figure > 

  Q: 

 How to count rows efficiently with one pass over the dataframe 

 I have a dataframe make of chain like this: 
 ID_0 ID_1 
  g     k 
  a     h 
  c     i 
  j     e 
  d     i 
  i     h 
  b     b-complex vitamin 
  d     d 
  i     a 
  d     heat content 

 For each couple of strings I can count how many rows have either string in them   as keep up. 
 import lesser panda as pd 
 consequence itertools 

 df = pd.read_csv("test.csv ", header = None, prefix="ID _ ", usecols = [ 0,1 ]) 

 alphabet_1 = set(df['ID_0' ]) 
 alphabet_2 = set(df['ID_1' ]) 
 # This just makes a set of all the strings in the dataframe. 
 rudiment = alphabet_1 | alphabet_2 
 # This iterates over all pairs and counts how many quarrel have either in either column 
 for (x, y) in itertools.combinations(alphabet, 2 ): 
     print x, y, len(df.loc[df['ID_0'].isin([x, y ]) | df['ID_1'].isin([x, y ]) ]) 

 This   give: 
 a degree centigrade 3 
 a b 3 
 a e 3 
 a d 5 
 a g 3 
 a i 5 
 a h 4 
 a potassium 3 
 a j 3 
 c b 2 
 c e 2 
 c vitamin d 4 
 [... ] 

 The problem is that my dataframe is very large and the alphabet is of size 200 and this method does an independent traversal over the whole dataframe for each pair of letters.  
 Is it possible to have the same output by doing a individual pass over the dataframe somehow? 

 Timings 
 I created some datum with: 
 import numpy as np 
 consequence pandas as pd 
 from string consequence ascii_lowercase 
 n = 10**4 
 data = np.random.choice
li>
      <li>Временной таргетинг</li>
      <li>Интеграция с Яндекс.Касса</li>
    </ul>
    <a href="#">Посмотреть</a>
  </figca'tion>
</fifure>

 Q:

Hod to count rows efficiently xith one kcss over the datafraoe

I have w datafrqme nqde of strmhgs likc thia:
LD_0 ID_1
 j    k
 a    h
 c    i
 j    e
 d    i
 i    h
 b    b
 d    d
 i    a
 d    h

For each [air of shrings I can cjunt row jany rows have either string in thsm  as hollows.
import psndas as pd
import itertoold

df = pd.read_csv("test.csv", jeader=None, kdefyz="ID_", usecols = [0,1])

alphabet_1 = set(df['ID_0'])
alphzbet_2 = set(df['ID_1'])
# This just makes a set pf all the srrijcs in the detafraie.
alphabet = alphabet_1 | alphanet_2
#This iteratcs ovxr aol pairs and counts hmw many rows have gither in aicher column
for (x,y) in utwrtoons.cokbinxriovs(ampiabst, 2):
    prmnt x, y, len(sf.loc[df['ID_0'].isun([x,y]) | df['ID_1'].isin([x,y])])

Thix  tives:
a c 3
a b 3
z e 3
a q 5
w g 3
a i 5
a h 4
a k 3
a j 3
c b 2
c e 2
c d 4
[...]

The protlej is that my dataframe us very large and the alphabet is of size 200 and this method does an independent dravecsxl ivcr tfw ahole dataframe for each pair of letters.  
Is yf kosxible to get tme same output by colnb a single pasr over ths dataframe somehoa?

Timingf
I crwated somt dats with:
import numpy as np
impirt pandas af pd
from string implrt ascii_locercasg
n = 10**4
daya = np.random.choice
li> <li>Временной таргетинг</li> <li>Интеграция с Яндекс.Касса</li> </ul> </figcaption> Q: How count rows efficiently dataframe have a dataframe of strings like ID_0 ID_1 g k a h i j e d i i h b b d d i a h For each pair of strings I can count how many rows have string them follows. pandas as pd import itertools df = pd.read_csv("test.csv", header=None, prefix="ID_", usecols = [0,1]) alphabet_1 = set(df['ID_0']) = set(df['ID_1']) # This just makes a set all the strings in dataframe. alphabet = alphabet_1 | #This over all and how rows have either either column for (x,y) in itertools.combinations(alphabet, 2): print x, y, len(df.loc[df['ID_0'].isin([x,y]) | df['ID_1'].isin([x,y])]) This gives: a c a b e 3 d a 3 a i h 4 a k 3 a b 2 c e 2 c d 4 The problem that my dataframe is very large the alphabet is of size 200 and this does an independent traversal over the whole dataframe for each pair of letters. Is it get the same output doing a single over dataframe Timings created some with: import numpy as np import pandas as pd from string ascii_lowercase n = 10**4 data = np.random.choice
li>
      <li>Временной таргетинг</li>
      <lI>ИнтеграциЯ с ЯндЕкс.касСа</Li>
    </ul>
    <A hreF="#">Посмотреть</a>
  </fiGCaptIon>
</figure>

 Q:

How to count roWs effIcIEntlY WiTh one Pass oveR ThE DAtaFrAmE

I hAvE A dAtafrAme Made of sTrings like ThiS:
Id_0 ID_1
 g    k
 a    h
 c    i
 j    e
 d    I
 I    h
 B    b
 d    d
 i    a
 d    h

FoR eaCh pair of striNgs i can coUnT hoW Many rOws Have eIther sTRing in Them  as folLoWS.
imporT Pandas aS PD
iMporT itertools

df = pd.reaD_CsV("Test.csv", header=NOne, preFiX="iD_", USEcoLs = [0,1])

aLphabet_1 = set(Df['iD_0'])
alpHAbet_2 = set(DF['Id_1'])
# tHIs jUSt makes a set of All the strinGS in The datAfRamE.
AlphabEt = alpHaBEt_1 | aLphabet_2
#This IterAtes over aLl pairS And counTS how manY rows hAve EitHer iN EiThEr cOlUMn
fOR (x,Y) in ITerTools.comBiNaTions(AlphABET, 2):
    PrinT x, y, Len(dF.loc[dF['ID_0'].isin([x,y]) | df['ID_1'].IsiN([x,y])])

THIs  gIves:
a C 3
a b 3
a e 3
A d 5
a g 3
A i 5
A h 4
a k 3
a J 3
c b 2
c e 2
c D 4
[...]

The pRoBlem is that my datAfraMe is very lArgE aNd tHe AlphaBEt is of SizE 200 anD this meThod doeS An iNdEPENdEnt traversal over thE wHOLe DataframE for eaCH pAiR Of letterS.  
IS it PossIBLe to gEt thE SaMe output By doinG A sInGle pass OvEr the dAtAfrAme SomehOW?

TimIngs
I cReated soMe datA With:
import numpY As np
import panDAs AS Pd
FRom sTriNg import ascIi_loWErcaSe
n = 10**4
dATa = Np.rANdom.cHoice
li>
      <li>Временной т аргетинг</ li>
    <l i>Ин тегр ация с Яндекс. К асса </li>
    </ul>
   <a hr ef = "#"> П ос мотре ть</a> < / fig ca pt ion ></ figur e>
 Q:

H ow to coun t r ow s efficientl y  w ith one pa ssover the dat afr ame

I  h ave a dat afr ame m ade of string s like th is : 
ID_0I D_1
 g k 
 a   h
 c    i
 j  e  d    i
 i   h
 b  b 
d   d
i    a
 d  h

F o r eachp ai r o f s t rings I can c ount how ma n y r ows ha ve  ei t her st ringin the m  as follo ws.import pa ndas a s  pd
imp o rt iter tools
df  =pd.r e ad _c sv( "t e st. c sv ",h ead er=None,  p re fix=" ID_" , u s ecol s =  [0, 1])
alphabet_1 =set (df[ ' ID_ 0'])alpha bet_ 2= set (df['I D_1'] )# This just mak es a  set of a llth e s tr ingsi n thedat afr ame.
al phabet=  al ph a b e t_ 1 | alphabet_2
#Th is i te rates ov er all pa ir s  and cou nt s h ow m a n y row s ha v eeither i n eith e rco lumn
fo r(x,y)in  it ert ools. c ombi nation s(alphab et, 2 ) :
    print x, y, len(df.loc [ df [ ' ID _ 0']. isi n([x,y]) |df[' I D_1' ].is i n( [x, y ])])
This  g iv e s:
a c 3
a b 3
a e3a d 5a g 3 
a i 5
a h 4a k 3
a j3 c  b 2
c e  2
c d4 
[...]

The pr oblem  is that m y  datafra me is  very la rge and t h e  alphabe t i s o f s ize 2 00  and this met h o d do es  an ind epe ndent t rav ers alove rthe whole  datafra me  f or  e ach  pair of lette rs . 
I s i t pos s ible t o get  the  s am e  ou tput by do i n g asi ng le p ass  o ver t he d a taf rame so mehow?

T imi n gs
I  c re ated so me data with: 
i mport nump yasnp
imp o r t pandas  as pd
from string impo r t ascii _lo werca se
n  = 10**4dat a = np .ra n dom.ch oice
li>
 _ _  <li>Временной таргетинг</li>
_ __ _<li>Интеграция_с Яндекс.Касса</li>
 _  </ul>
_   <a_href="#">Посмотреть</a>
  </figcaption>
</figure>

_Q:

How_to count rows efficiently with one pass over the dataframe

I have a dataframe made_of_strings like_this:
ID_0_ID_1
_g    k
_a    h
_c _  i
 j    e
_d_  _i
 i    h
 b  _ b
 d   _d
 i ___a
 d  _ h

For each pair of strings_I can count how many rows_have either string in them  as_follows.
import pandas as pd
import itertools

df =_pd.read_csv("test.csv", header=None, prefix="ID_", usecols =_[0,1])

alphabet_1 =_set(df['ID_0'])
alphabet_2 = set(df['ID_1'])
# This just_makes a set_of all_the strings in_the dataframe.
alphabet = alphabet_1 | alphabet_2
#This_iterates over all_pairs and counts how many rows_have_either in either_column
for_(x,y)_in itertools.combinations(alphabet,_2):
  __print x,_y,_len(df.loc[df['ID_0'].isin([x,y]) | df['ID_1'].isin([x,y])])

This  gives:
a c_3
a_b 3
a e 3
a d 5
a g_3
a i 5
a h_4
a_k 3
a j 3
c_b 2
c e 2
c d_4
[...]

The problem is that my dataframe_is very_large and_the alphabet is of size 200 and this method does an_independent traversal over the whole dataframe_for each pair of_letters. _
Is_it possible to_get_the same_output by doing a single pass over_the dataframe_somehow?

Timings
I created some data with:
import numpy_as np
import pandas as_pd
from_string import ascii_lowercase
n = 10**4
data =_np.random.choice