✏️
rjnotes
  • Home
  • Books To Read in 2023
  • Mac & Ubuntu Commands - v2
  • DevOps Tasks
  • AWS Commands
  • AWS IAM Policies
  • Autoscaling Automation
  • Shell Commands - Unix
  • RJTools
  • Github
  • VAP
  • virtualenv
  • Alembic Commands
  • Aerospike commands
  • AWS Lambda Commands
  • AWS Glue Commands
  • AWS IAM Policies
  • Azure Commands
  • Cassandra Commands
  • Clickhouse Commands
  • Conda Commands
  • Docker Commands
  • IV Assignments
  • AWS Pricing
  • LangChain Commands
  • Python templates
  • PyLint
  • Pandas Commands
  • CICD
  • GitBook - How to publish
  • HTTPS Fix
  • Video Fix
  • Sublime
  • YT Videos
  • Template
  • GenAI Cards
  • Assignment Validator
  • Auth
  • Decision Maker Persona
  • Session Time
  • New Language Learning
  • Finnish Learning
  • Paste Image Extension
  • Director vs Head vs VP
Powered by GitBook
On this page

Was this helpful?

Pandas Commands

get only dataframe which one column values length is greater than 0

To filter a DataFrame such that only the rows where the length of the string in a specific column is greater than 0 are returned, you can use the .str.len() method combined with a boolean indexing in pandas. Here's an example demonstrating how to do this:

Suppose you have a DataFrame named df with a column named 'ColumnA', and you want to filter out all rows where the length of the string in 'ColumnA' is greater than 0:

import pandas as pd

# Sample DataFrame
data = {
    'ColumnA': ['text', '', 'more text', '', 'even more text'],
    'ColumnB': [1, 2, 3, 4, 5]
}
df = pd.DataFrame(data)

# Filter the DataFrame
filtered_df = df[df['ColumnA'].str.len() > 0]

print(filtered_df)

This code snippet will create a DataFrame that only includes the rows where 'ColumnA' contains a string with length greater than 0, effectively excluding rows where 'ColumnA' is an empty string.


How to show all rows in pandas?

To display all rows in a pandas DataFrame, you can adjust the display settings using pd.set_option(). Specifically, you can set the "display.max_rows" option to None or a sufficiently high number to ensure that all rows are displayed when you print a DataFrame.

Here's how you can do it:

import pandas as pd

# Assuming df is your DataFrame

# Set option to display all rows
pd.set_option('display.max_rows', None)

# Now, when you print the DataFrame, all rows will be displayed
print(df)

# Reset display options to default
pd.reset_option('display.max_rows')

PreviousPyLintNextCICD

Last updated 1 year ago

Was this helpful?