i want write list csv,when trying receive below error
out.writerows(fin_city_ids) _csv.error: iterable expected, not numpy.int64
my code below
org_id.append([pol_id,bldest_id]) fin_ids=list(org_city_id['org_id'].unique()) print(fin_ids) out = csv.writer(open("d:/dataset/fin_ids.csv","w"), delimiter='|') out.writerows(fin_ids)
below output fin_ids
[1002774, 0, 1000702, 1000339, 1001620, 1000710, 1000202, 1003143, 147897, 31018, 1001502, 1002812, 1003026, 1003280, 1003289, 1002714, 133191, 5252218, 6007821, 1002632]
org_id dataframe contains duplicate ids .fin_ids list contains unqiue values of ids .fin id list of unique ids derived data frame org_id.
output desired csv values in separate rows going load data sql table later .
you can done in many ways. if wish writerows
csv
module, have turn list fin_ids
sequence of lists first:
fin_ids = [1002774, 0, 1000702, 1000339, 1001620, 1000710, 1000202, 1003143, 147897, 31018, 1001502, 1002812, 1003026, 1003280, 1003289, 1002714, 133191, 5252218, 6007821, 1002632] outfile = open('d:/dataset/fin_ids.csv','w') out = csv.writer(outfile) out.writerows(map(lambda x: [x], fin_ids)) outfile.close()
another way use .to_csv()
method pandas series
. since started dataframe, do:
org_city_id['org_id'].unique().to_csv("d:/dataset/fin_ids.csv", index=false)
both of these should generate csv file following data:
1002774 0 1000702 1000339 1001620 1000710 1000202 1003143 147897 31018 1001502 1002812 1003026 1003280 1003289 1002714 133191 5252218 6007821 1002632
Comments
Post a Comment