Answer the question
In order to leave comments, you need to log in
How to make conditions in pandas by SQL query type?
Good day)
I am writing a small script for pandas and I need to solve one problem.
How can I make an action in pandas that in SQL looks like this:
SELERCT *
FROM table_name
WHERE 'Custom Label (SKU)' LIKE 'A%'
import pandas as pd
import os
my_xlsx=[]
for root, dirs, files in os.walk(r'D:\ebay'):
my_xlsx.extend([os.path.join(root, file) for file in files if file.endswith('.xlsx')])
dirs.clear()
ebay = pd.DataFrame()
for i in my_xlsx:
ebay=ebay.append(pd.read_excel(i, sheet_name="Listings", skiprows=2))
shopify = pd.read_csv(r'D:\shopify\shopify.csv', sep =',', encoding="utf-8", header=None)
ebay['C:Season'] = ebay['C:Season'].str.replace("\|\|", ', ')
ebay = ebay['Custom Label (SKU)'].str.startswith('A', na=False)
Answer the question
In order to leave comments, you need to log in
For the LIKE 'A%' query, you have the correct variant written, via startswith.
Perhaps you need to deal with regexps in LIKE and need, for example, LIKE '%A%' - then use contains. Well, do not forget about case sensitivity (the case parameter).
ebay = ebay['Custom Label (SKU)'].str.contains('a', case=False)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question