SHARE
TWEET

Untitled

a guest Aug 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. data=pd.read_csv('file.csv', sep=';', decimal=',')
  3. dat=pd.DataFrame(data.T)
  4. for i in dat:
  5.     if dat[dat.columns[i]][1]==dat[dat.columns[i]][2]:
  6.         a=dat.columns[i]
  7.      
  8. data = pd.read_csv('file.csv', sep=';', decimal=',',  quotechar="'").query('seller != buyer')
  9.      
  10. data.to_csv('output.csv', index=False)
  11.      
  12. 'id';'seller';'buyer';'timestamp'
  13. 1;seller-1;buyer-1;2016-01-01
  14. 2;seller-2;buyer-2;2016-01-02
  15. 3;same-1;same-1;2016-01-11
  16. 4;same-2;same-2;2016-01-22
  17.      
  18. In [21]: pd.read_csv(r'D:tempbuyer_seller.csv', sep=';')
  19. Out[21]:
  20.    'id'  'seller'  'buyer' 'timestamp'
  21. 0     1  seller-1  buyer-1  2016-01-01
  22. 1     2  seller-2  buyer-2  2016-01-02
  23. 2     3    same-1   same-1  2016-01-11
  24. 3     4    same-2   same-2  2016-01-22
  25.  
  26. In [22]: pd.read_csv(r'D:tempbuyer_seller.csv', sep=';', quotechar="'")
  27. Out[22]:
  28.    id    seller    buyer   timestamp
  29. 0   1  seller-1  buyer-1  2016-01-01
  30. 1   2  seller-2  buyer-2  2016-01-02
  31. 2   3    same-1   same-1  2016-01-11
  32. 3   4    same-2   same-2  2016-01-22
  33.  
  34. In [23]: pd.read_csv(r'D:tempbuyer_seller.csv', sep=';', quotechar="'").query('seller != buyer')
  35. Out[23]:
  36.    id    seller    buyer   timestamp
  37. 0   1  seller-1  buyer-1  2016-01-01
  38. 1   2  seller-2  buyer-2  2016-01-02
  39.      
  40. In [27]: df = pd.read_csv(r'D:tempbuyer_seller.csv', sep=';')
  41.  
  42. In [28]: df.columns.tolist()
  43. Out[28]: ["'id'", "'seller'", "'buyer'", "'timestamp'"]
  44.  
  45. In [30]: df.columns = df.columns.str.replace("'", '')
  46.  
  47. In [31]: df.columns.tolist()
  48. Out[31]: ['id', 'seller', 'buyer', 'timestamp']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top