108640 Views
83860 Views
59555 Views
48723 Views
48311 Views
47806 Views
Build a laser-cut robot
Robots and Lasers
Arduino Plug and Make Kit Review
Pi to Pico W Bluetooth Communication
Two-Way Bluetooth Communication Between Raspberry Pi Picos
Gamepad 2
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
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 >