101591 Views
79842 Views
45596 Views
44332 Views
40991 Views
33419 Views
Raspberry Pi Time machine
Now Ad-Free
Guiding Light
Sync Files on your Pis, with Syncthing
NextCloud
Buddy Jr.
Introduction to FreeCAD for Beginners
Building a Robot Arm with Raspberry Pi and PCA9685
Building User Authentication for Static Sites with FastAPI
Mastering Pydantic for Robust Data Validation
Mastering Markdown for Documentation with Jekyll
Introduction to Rust
KevsRobots Learning Platform
40% Percent Complete
By Kevin McAleer, 2 Minutes
Welcome to the lesson on Basic Operations with Data Frames in Pandas. Data Frames are central to data manipulation in Pandas, and knowing how to effectively perform various operations on them is key to unlocking their full potential. This lesson covers essential techniques like selection, filtering, sorting, and basic computations.
To select a single column, use the column label:
# Selecting a single column selected_column = df['ColumnName']
To select multiple columns, use a list of column labels:
# Selecting multiple columns selected_columns = df[['Column1', 'Column2']]
Rows can be selected by their position using iloc or by index using loc:
iloc
loc
# Selecting rows by position rows_by_position = df.iloc[0:5] # First five rows # Selecting rows by index rows_by_index = df.loc['IndexLabel']
You can filter data based on conditions:
# Filtering data filtered_data = df[df['ColumnName'] > value]
Data in a Data Frame can be sorted by the values of one or more columns:
# Sorting data sorted_data = df.sort_values(by='ColumnName')
Pandas allows for basic statistical computations:
# Basic computations mean_value = df['ColumnName'].mean() sum_value = df['ColumnName'].sum()
You can drop rows or columns from a Data Frame:
# Dropping rows df_dropped_rows = df.drop([0, 1, 2]) # Dropping columns df_dropped_columns = df.drop(['Column1', 'Column2'], axis=1)
Axis Note that axis=1 indicates that the operation should be performed on columns, whereas axis=0 indicates that it should be performed on rows.
Note that axis=1 indicates that the operation should be performed on columns, whereas axis=0 indicates that it should be performed on rows.
axis=1
axis=0
In this lesson, we have covered the basics of data selection, filtering, sorting, and performing basic computations in Pandas. These operations are fundamental to data manipulation and analysis.
< Previous Next >