Delete column and make next row column?

Viewed 62

If I have a column that I want to delete entirely and make the very next row the columns how can I do that?

For example if I have

unnamed column 0 | unnamed column 1 | unnamed column 2 
    Year            Month               Day
    1900             04                  11

New df

Year |  Month | Day
1900     04      11

Thanks

2 Answers

In case you are using pandas, would this work?

import pandas as pd

old_df = pd.DataFrame([["a", "b", "c"], ["Year", "Month", "Day"], [1990, 4, 11]])
new_df = old_df.loc[2:, :]
new_df.columns = old_df.loc[1, :]

print(old_df)
print(new_df)
  1. Create another table with the structure that you want
  2. migrate the data with the conversion
  3. Delete the original table

Else you can make a function or some other process in order to access the data via
...
if Table.unamedCollum0 is like 'Year' then Table.unamedCollum0 = Table.unamedCollum0.old
...

Related