3

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

1
  • 3
    You can use skiprows in pandas.read_csv(). Is that what you are looking for? Commented Aug 20, 2020 at 16:32

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

0
  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
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.