Python Data table -
i have data textfile called “data” delimited comma in each row.
the first 3 lines of file following:
“(1,abc,abcde)”,”24” “(10,abd,abc11)”,”12” “(6,abe,aberd)”,”39”
in file, values in each row string , integer.
i first read file:
target=pd.read_csv(’data',sep=',',names=[‘col1’,'col2’])
what want see in target table following 5 column table:
cola colb colc col1 col2 1 abc abcde (1,abc,abcde) 24 10 abd abc11 (10,abd,abc11) 12 6 abe aberd (6,abe,aberd) 39
what tried was:
for index,row in target.iterrows(): tup=tuple(row[0][1:len(row[0])-1].split(",")) target[’cola'][index]=tup[0] target[’colb'][index]=tup[1] target[’colc'][index]=tup[2]
this done change string tuple can create new columns target datatable. delete col1
code above doesn't work reason. crashes..
your code peppered "smart quotes": “”
instead of "
, ‘’
instead of '
. remove them , replace them corresponding straight ("dumb") quotes, straight quotes have python meaning you're looking for.
Comments
Post a Comment