We writepd.in front ofDataFrame()to let Python know that we want to activate the DataFrame() function from the Pandas library. Be aware of the capital D and F in DataFrame! Interpreting the Output This is the output: We see that "col1", "col2" and "col3" are the names of the ...
Add the content of one DataFrame to another:import pandas as pddata1 = { "name": ["Sally", "Mary", "John"], "age": [50, 40, 30]}data2 = { "qualified": [True, False, False]}df1 = pd.DataFrame(data1)df2 = pd.DataFrame(data2) newdf = df1.join(df2) ...
Return a DataFrame with only the "name" and "age" columns:import pandas as pddata = { "name": ["Sally", "Mary", "John"], "age": [50, 40, 30], "qualified": [True, False, False]}df = pd.DataFrame(data)newdf = df.filter(items=["name", "age"]) ...