create a new dataframe from existing dataframe python code example

Example 1: python create new pandas dataframe with specific columns

# Basic syntax:
new_dataframe = old_dataframe.filter(['Columns','you','want'], axis=1)

Example 2: create dataframe with column names pandas

In [4]: import pandas as pd
In [5]: df = pd.DataFrame(columns=['A','B','C','D','E','F','G'])
In [6]: df
Out[6]:
Empty DataFrame
Columns: [A, B, C, D, E, F, G]
Index: []

Example 3: copy only some columns to new dataframe in r

new = old[['A', 'C', 'D']].copy()