this note consists of:
- read csv using pandas
- dataframe iteration
- split string in python
- sample dictionary python
import pandas as pd train = pd.read_csv(r"<csv path>", sep='\t', header=0) #train.category_name.value_counts().plot(kind='bar', grid=True, figsize=(16, 9)) #this is dictionary listCat = {} for index, row in train.iterrows(): # sample split print(index) if len(row["category_name"].split("/")) > 1: for s in row["category_name"].split("/"): temp = 0 # sample check key in dictionary if s in listCat: temp = listCat[s] listCat[s] = temp + 1 print(listCat) |
CMIIW
Leave a Reply