As part of the development of a new GeoProcessing tool (in 10.3) I am using the Transpose Fields (arcpy.TransposeFields_management) in a small python script to transpose a horizontal line of data in a table to a vertical line. While the code works and takes the data I require and adds it to the new tables it does not seem to place the data in the correct order.
Has anyone come across any issues like this with Transpose Fields or am I doing something wrong in the code?
See code (name of the field in the original table and the new name in PopSummaryT i.e Sum_Pop_T11 TotalPopulation) and image of output below: You will see that the order is different in the Table as set out in the code.
arcpy.TransposeFields_management("PopSummary", "Sum_Pop_T11 TotalPopulation;Sum_Pop_014T11 Pop014;Sum_Pop_1524T1 Pop1524;Sum_Pop_2544T1 Pop2544;Sum_Pop_4564T1 Pop4564;Sum_Pop_65pT11 Pop65p", "PopSummaryT", "Indicator", "Census2011", "")
Another interesting point is that if I delete one or two of fields from the code then the order in the table is different again.
Not sure what is happening here but if someone has any advice it would be great.
well my only guess is what it is not... the transposition is not based on a list, but another container which doesn't maintain input order... my guess is a dictionary is being used
Thanks for your reply.
It just seems to be very random and throws back different results depending on names that are entered. I thought it may be alphabetical but even when I added a prefix of A_, B_ to the new field names it was still jumbled up.
Testing the actual TransposeField Tool also throws back a similar result. Would you know how I could report this to ESRI developers?
I would, or at the very least get them to clarify the sort order. It could definitely be a bug given the example they use in the help topic, but not that use by the results.. As another thought, you aren't using alias for the field names which would through the initial entry off?
No, it just seems to be a random sort. I've some up with a bit of a work around using alpha codes, the do a sort management (ascending), join to a another tables with the alpha codes and proper variable names and finally use delete field to clear out the junk. It's a bit of a mess but works none the less!
Would you know where I can send in an official bug?