111763 Views
85221 Views
83639 Views
51774 Views
49949 Views
48472 Views
Obsidian - the best tool for Makers
10 Projects for your Raspberry Pi Pico
Raspberry Pi Telegraf Setup with Docker
Setting Up Dynamic DNS on a Raspberry Pi for Self-Hosting
Raspberry Pi WordPress Setup with Docker
Raspberry Pi WireGuard VPN Setup with Docker
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
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 >