Skip to content

Instantly share code, notes, and snippets.

@choyan
Created July 29, 2017 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choyan/75e060c14d05d2ffdf088bfe5028ad29 to your computer and use it in GitHub Desktop.
Save choyan/75e060c14d05d2ffdf088bfe5028ad29 to your computer and use it in GitHub Desktop.
bid brand web_site
1 sqaure sqaure.com.bd
2 beximco beximco.com.bd
2 beximco beximco.com.bd
2 beximco beximco.com.bd
import numpy as np
import pandas as pd
brand = pd.read_csv("brand.csv")
product = pd.read_csv("product.csv")
product['brand_id'] = np.where((brand['brand'] == product['brand']), brand['bid'], np.nan)
product['brand_id'] = product['brand_id'].apply(np.int64)
product.to_csv("newdata.csv", index=False)
pid brand_id brand product_name address
1 1 sqaure napa extra null
2 2 beximco arixon null
3 2 beximco Arlin
4 2 beximco Clinacyn
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 5 columns, instead of 4. in line 4.
pid,brand_id,brand,product_name,address
1,null,sqaure,napa extra,null
2,null,beximco,arixon,null
3,null,beximco,Arlin,
4,null,beximco,Clinacyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment