[Solved] Scraped CSV pandas dataframe I get: ValueError(‘Length of values does not match length of ‘ ‘index’)


You need merge with inner join:

print('####CURRIES###')
df1 = pd.read_csv('C:\\O\\df1.csv',
                   index_col=False,
                   usecols=[0,1,2],
                   names=["EW", "WE", "DA"],
                   header=None)
print(df1.head())
####CURRIES###
                                 EW    WE  \
0                         can v can  1.90   
1    Lanus U20 v Argentinos Jrs U20  2.10   
2      Botafogo RJ U20 v Toluca U20  1.83   
3  Atletico Mineiro U20 v Bahia U20  2.10   
4                 FC Porto v Monaco  1.36   

                                                  DA  
0  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  
1  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  
2  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  
3  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  
4  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  

print('####Mangoes###')
df2 = pd.read_csv('C:\\O\\df2.csv',
                   index_col=False,
                   usecols=[0,1,2, 3, 4],
                   names=["AA", "AB", "AC", "AD", "AE"],
                   header=None)

print(df2.head())
####Mangoes###
            AA                     AB                      AC      AD  \
0  Today 19:00          Indonesia U23          Kyrgyzstan U23  650.00   
1  Today 23:00  Brunei Darussalam U23            Mongolia U23    3.30   
2  Today 19:30                    can                     can  110.00   
3  Today 20:00  FC Zbrojovka Brno U19       Sparta Prague U19    1.97   
4  Today 20:30         Rahmatgonj MFS  Sheikh Jamal Dhanmondi    1.51   

                                                  AE  
0  https://www.betfair.com.au/exchange/plus/footb...  
1  https://www.betfair.com.au/exchange/plus/footb...  
2  https://www.betfair.com.au/exchange/plus/footb...  
3  https://www.betfair.com.au/exchange/plus/footb...  
4  https://www.betfair.com.au/exchange/plus/footb...  

#crewte new column called EW in df2
df2['EW'] = df2['AB'] + ' v ' + df2['AC']   
#merge on columns EW  
df3 = pd.merge(df2, df1, on='EW')
#change columns names
df3 = df3.rename(columns={'WE':'O1','AD':'O2'})
#subtract O columns
df3['D'] = df3['O2'].sub(df3['O1'], fill_value=0)
print (df3)
            AA             AB              AC     O2  \
0  Today 19:00  Indonesia U23  Kyrgyzstan U23  650.0   
1  Today 19:30            can             can  110.0   

                                                  AE  \
0  https://www.betfair.com.au/exchange/plus/footb...   
1  https://www.betfair.com.au/exchange/plus/footb...   

                               EW   O1  \
0  Indonesia U23 v Kyrgyzstan U23  2.0   
1                       can v can  1.9   

                                                  DA      D  
0  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  648.0  
1  https://www.bet365.com.au/#/AC/B1/C1/D13/E40/F...  108.1  

solved Scraped CSV pandas dataframe I get: ValueError(‘Length of values does not match length of ‘ ‘index’)