I have a method that creates a list, results, and then appends to it a dict row which has keys (column names in my eventual dataframe) and values (row values in my eventual dataframe). Then I append the row and convert the results collection to a df at the end. For example:
results = []
row = {}
row['Name']="alice"
row['Age']=3
results.append(row)
..reset row, fill in values like above, and append more rows..
df = pd.DataFrame(results)
The issue I have is that the column names are alphbetized so the df looks like this:
df.head()
|Age | Name |
|3 | alice |
Is there a way to specify the column names to be in the order I want ("Name", "Col")? In reality I have many more columns so I'd prefer not to have to do:
cols = df.columns
cols = cols[:1] + cols[0:1]
and manually rearrange it. However, if I do so, does that just move around the column row or also the rows below? So, will "alice" and 3 in the row below also get moved around while moving the column as one would expect?