I have two inventory csv, one is the updated version of the other; the new one can have new rows with keys not presents in old one; missing row for keys no more presents; same keys with updated records:
sku nome prezzo qty codice
1 uno 10 1 11111
2 due 10 1 22222
3 tre 10 1 33333
4 quattro 10 1 44444
5 cinque 10 1 55555
10 dieci 10 1 101010
sku nome prezzo qty codice
1 uno 20 2 11111
2 due 20 2 22222
3 tre 20 2 33333
5 cinque 20 2 55555
10 dieci 20 2 101010
11 undici 20 2 111111
with reindex union I can menage to have my desired result:
In [52]: r = b.set_index('sku') \
...: .reindex(pd.Index(a['sku']).union(pd.Index(b['sku']))) \
...: .combine_first(a.set_index('sku').assign(qty=0, prezzo=0)) \
...: .reset_index()
sku nome prezzo qty codice
0 1 uno 20 2 11111
1 2 due 20 2 22222
2 3 tre 20 2 33333
3 4 quattro 0 0 44444
4 5 cinque 20 2 55555
5 10 dieci 20 2 101010
6 11 undici 20 2 111111
Now, if the new files had same colums + other that aren't presents in old one,the result is right but I have column rearranged; how to keep the column structure of new file?
(new file with new colums structure):
sku nome prezzo qty codice Acolumn Bcolumn
0 1 uno 20 2 11111 kkkk
1 2 due 20 2 22222 qwerty
2 3 tre 20 2 33333 mmmm
3 4 quattro 0 0 44444
4 5 cinque 20 2 55555
5 10 dieci 20 2 101010 ssss
6 11 undici 20 2 111111 1a2b3c4d
or
sku nome Acolumn prezzo qty codice Bcolumn
0 1 uno kkkkk 20 2 11111
1 2 due 20 2 22222 qwerty
2 3 tre 20 2 33333
3 4 quattro 0 0 44444
4 5 cinque 20 2 55555
5 10 dieci 20 2 101010
6 11 undici 20 2 111111
reindexoperation! Anyway, I've tried to improve your solution."other columns, that aren't presents in old one"and your desired data set?