python pandas read in csv file1 like this: name string a1 b1 a2 b2 a3 b3 ..... I have another csv file2, but in different order. a3 a1 a2... I like to find the the matching b string for each row in csv2 file, and write them out to csv file 3 like this: a3 b3 a1, b1 a2 b2 Is there an easy way to do this using Python?
name string a1 b1 a2 b2 a3 b3 ..... I have another csv file2, but in different order.
a3 a1 a2...
I like to find the the matching b string for each row in csv2 file, and write them out to csv file 3 like this:
a3 b3 a1, b1 a2 b2
Is there an easy way to do this using Python?
Great, thanks and I will give it a try.
最基本的indexing就搞定了。
Could you provide more details on the map function? thanks.
more details or example? thanks
啥还有门? 我从来就不管有没有门,直接走就行了。 我想自动化我的pet project。
可以用merge把兩個表按name這一列的值拼起來
多谢多谢,我试试看。
csv2读进来读成list 循环 找对应csv1生成的dict key 把对应的dict item 存到csv3
myDataFrame['column1'].map(myDict)
如果不是unique value,建map会出错吧。用pdf.merge 方便省事
cat file1.txt file2.txt | awk 'NF>1{a{$1}=$2;} NF==1{print $1" "a{$1}}
这俩string 排序是不一样的吧, 也就是说a1和b1在各自的csv中读进来的话 如果是存成dict hash过去的list,index是不一样的。 除非这辆 csv你有一个共同的格外colume用于判断排序
比如 如果 A.csv,读进来的dict, A1这个key 下面就是一个list [a1,a2,a3] ,额外something 这个key下面就是[k1,k2,k3] ,你也可以建一个 k 到a 的dict A1 额外something a1 k1 a2 k2 a3 k3
B.csv 同样做法 B1 额外something b3 k3 b2 k2 b1 k1
这样通过共同的k 来找到mapping 关系。