Pandas: Create a smaller dataframe with a subset of all features
Write a Pandas program to create a smaller dataframe with a subset of all features.
Sample Solution:
Python Code :
import pandas as pd
df = pd.read_csv('movies_metadata.csv')
# Create a smaller dataframe
small_df = df[['title', 'release_date', 'budget', 'revenue', 'runtime']]
print("Smaller DataFrame:")
print(small_df.head())
Sample Output:
Smaller DataFrame: title release_date budget revenue runtime 0 Toy Story 1995-10-30 30000000 373554033 81.0 1 Jumanji 1995-12-15 65000000 262797249 104.0 2 Grumpier Old Men 1995-12-22 0 0 101.0 3 Waiting to Exhale 1995-12-22 16000000 81452156 127.0 4 Father of the Bride Part II 1995-02-10 0 76578911 106.0
Python-Pandas Code Editor:
Sample Table:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to get the details of fifth movie of the DataFrame.
Next: Write a Pandas program to display the first 10 rows of the DataFrame.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics