0

Suppose I have a dataframe A, a dataframe B, a dataframe C,with the following data:

Dataframe A:

Name   |  ID | Birthda  | Age   | Hobbies| WebPage |  
 ------|-----|----------|-------|--------|---------|-- 
  ...  | ... | ...      | ...   | ...    | ...     |  
  ...  | ... | ...      | ..... | ....   | ....    |  
  ...  | ..  | ...      | ...   | ...    | .....   |  

Dataframe B

 Name  | Experience | Places | Foods | Languages 
 ------|------------|--------|-------|----------- 
  ...  | .......    | ...... | ..... | .......   
  ...  | .....      | .....  | ..... | ......    
  ...  | ...        | ....   | ....  | .....     
       |            |        |       |           

Dataframe C

Actor   | Movies | Places | Date | Animals | Music 
 -------|--------|--------|------|---------|------- 
  ...   | ....   | ....   | ...  | ....    | ....  
  ....  | ....   | ....   | .... | ....    | ....

So, I'm only interested in the headers( columns names), I need to crate a csv that contains the dataframe's names as the csv file header and the headers as elements of each csv columns. The csv file must be Like this:

DataframeA   | DataframeB | DataframeC  |  
 ------------|------------|------------|-- 
  Name       | Experience | Actor      |  
  ID         | Name       | Movies     |  
  Birthday   | Places     | Places     |  
  Age        | Foods      | Date       |  
  Hobbies    | Languages  | Animals    |  
  WebPage    |            | Music      |

1 Answer 1

1

Simply

pd.DataFrame({'DataFrame A': dfa.columns, 
              'DataFrame B': dfb.columns, 
              'DataFrame C': dfc.columns}).to_csv('file.csv')

if you have same length.

For different lengths,

pd.DataFrame([dfa.columns, 
              dfb.columns, 
              dfc.columns], index=['DataFrame A', 'DataFrame B', 'DataFrame C']).T.fillna('').to_csv('file.csv')
Sign up to request clarification or add additional context in comments.

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.