How to use python pandas to find a specific string in various rows

2024/7/6 21:30:27

I am trying to do my taxes. I have over 2,000 rows of data in a CSV of orders. I am trying to just count and print the rows that contain "CA" so I know the ones I need to pay sales tax on. I understand I can do this with python using the pandas library. I am stuck trying to get it to work though. Any help is appreciated.

Answer

You can try this code below:

import pandas as pddf = pd.read_csv(r'your csv file path')
res = df[(df.apply(lambda s: s.eq('CA').any(), axis=1))]
print(res)
https://en.xdnf.cn/q/120490.html

Related Q&A

How to cast a list to a dictionary

I have a list as a input made from tuples where the origin is the 1st object and the neighbour is the 2nd object of the tuple. for example :inp : lst = [(a,b),(b,a),(c,),(a,c)] out : {a: (a, [b, c]), …

Couldnt get rid of (_tkinter.TclError: bad event type or keysym UP) problem

I am running a Linux mint for the first time . I tried coding a python problem but for two days I am continiously facing problems due to Linux interface please This is my code:-import turtleimport time…

WMI lib to start windows service remotely

How do I start a service using the WMI library? The code below throws the exception: AttributeError: list object has no attribute StopServiceimport wmi c = wmi.WMI (servername,user=username,password=p…

TutorialsPoint - Flask – SQLAlchemy not working

I did all that was stated on tutorial point (just copied and pasted), but when I tried to add a student entry,i.e. ‘Add Student’ it givesBad Request The browser (or proxy) sent a request that this se…

Implement f-string like magic to pimp Djangos format_html()

I would like to pimp format_html() of Django. It already works quite nicely, but my IDE (PyCharm) thinks the variables are not used and paints them in light-gray color:AFAIK f-strings use some magic re…

Selecting a set of numbers from a list which add up to a given value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 9…

List of even numbers at even number indexes using list comprehension [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 9…

How do I check if a list of lists exists in a list of lists?

I got a list of lists b and I want to check if they exist in list a which is also a list of lists. Im currently using the following method which is quite time-consuming. Is there a faster way? b = [[…

How do i print out a number triangle in python? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Real time clock display in Tkinter

I want to create real time clock using Tkinter and time library. I have created a class but somehow I am not able to figure out my problem.My codefrom tkinter import *import timeroot = Tk()class Clock:…