8 为 : -10 29
import csv
import numpy as np
import pandas as pd
csv_file = 'Bruv.csv'
names = []
Bar = []
Price = []
with open(csv_file, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
names.append(row.get('Sizes'))
Bar.append(row.get('Product'))
Price.append(row.get('Price'))
GG = pd.DataFrame()
GG['Sizes'] = names
GG['Bars'] = Bar
GG['Prices'] = Price
print(GG)
Bar=np.array(Bar).astype('str').tolist()
print("The array:", Bar)
这是我的代码,CSV是
在循环中你可以这样做,
Product.append("'"+row.get('Product')+"' ="+row.get('Price')) #if u need as string
or
Product.append({ "'"+row.get('Product')+"': "+row.get('Price')+"}") #if u need as dictionary