Advertisement
shoaib-santo

Pandas DataFrame Cheatsheet

Nov 4th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. 1. Load CSV into DataFrame: df = pd.read_csv('filename.csv')
  2. 2. Get Shape (Number of Rows and Columns): df.shape
  3. 3. Get Summary Information: df.info()
  4. 4. Displaying the First Few Rows of the DataFrame: df.head(10)
  5. 5. List Column Names: df.columns
  6. 6. Access a Specific Column: df['ColumnName'] # Example: f['Country name']
  7. 7. Access Specific Row by Index: df.iloc[index] # Example: f.iloc[4]
  8. 8. Filter Rows by Condition: df[df['ColumnName'] == 'Value'] # Example: f[df['Continent'] == 'Asia']
  9. 9. Save Filtered Data to CSV: df[df['Continent'] == 'Asia'].to_csv('asia.csv', index=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement