alex_bn_lee

导航

[965] Generate a new empty DataFrame with the same columns as an existing DataFrame in Pandas

To generate a new empty DataFrame with the same columns as an existing DataFrame in Pandas, you can use the pd.DataFrame constructor and pass the columns from the existing DataFrame. Here's an example:

import pandas as pd

# Sample DataFrame
existing_df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

# Create a new empty DataFrame with the same columns
new_empty_df = pd.DataFrame(columns=existing_df.columns)

print(new_empty_df)

In this example, pd.DataFrame(columns=existing_df.columns) creates a new empty DataFrame (new_empty_df) with the same columns as the existing_df.

Adjust the columns and other parameters based on your specific use case.

posted on 2024-02-08 13:55  McDelfino  阅读(2)  评论(0编辑  收藏  举报