get rows with empty dates pandas python

2024/10/11 12:29:29

it looks like this:

      Dates  N-D  unit
0  1/1/2016  Q1   UD
1            Q2   UD
2            Q3   UD
3  2/1/2016  Q4   UD
4  5/1/2016  Q5   UD
5            Q6   UD

I want to filter out the empty Dates rows and save it in a dataframe blankDate:

      Dates  N-D  unit
1            Q2   UD
2            Q3   UD
5            Q6   UDblankDate=df1[df1['Dates']== '']  #this didn't work df1['Discharge Date'] = pd.to_datetime(df1['Discharge Date']) #then I converted the column to date format but still doesn't work

if the column is a string this piece of code works, it also works on numbers I think

blankDate=df1[df1['stringcolumn']== '']

but how do I compare to empty date rows?

Answer

One way would be to replace empty cells by nan and then use isnull()

df.Dates = df.Dates.replace('', np.nan)
blankDate = df[df.Dates.isnull()]
https://en.xdnf.cn/q/69775.html

Related Q&A

Python: Gridsearch Without Machine Learning?

I want to optimize an algorithm that has several variable parametersas input.For machine learning tasks, Sklearn offers the optimization of hyperparameters with the gridsearch functionality.Is there a …

Pandas division (.div) with multiindex

I have something similar to thisdf = pd.DataFrame(np.random.randint(2, 10, size = (5, 2))) df.index = pd.MultiIndex.from_tuples([(1, A), (2, A), (4, B), (5, B), (8, B)]) df.index.names = [foo, bar] df.…

Add a delay to a specific scrapy Request

Is it possible to delay the retry of a particular scrapy Request. I have a middleware which needs to defer the request of a page until a later time. I know how to do the basic deferal (end of queue), a…

importing without executing the class - python

my problem is about i have a file that contain class and inside this class there is bunch of code will be executed so whenever i import that file it will executed ! without creating an object of the…

If a command line program is unsure of stdouts encoding, what encoding should it output?

I have a command line program written in Python, and when I pipe it through another program on the command line, sys.stdout.encoding is None. This makes sense, I suppose -- the output could be another…

How to generate JSON-API data attribute vs results attribute in Django Rest Framework JSON API?

I have a django 1.9.2 project using Django Rest Framework JSON API:https://github.com/django-json-api/django-rest-framework-json-api:My viewset looks like this:class QuestionViewSet(viewsets.ReadOnlyMo…

How connect my GoPro Hero 4 camera live stream to openCV using Python?

I m having troubles trying to capture a live stream from my new GoPro Hero 4 camera and do some image processing on it using openCV.Here is my trial (nothing shows up on the created windowimport cv2 im…

I thought Python passed everything by reference?

Take the following code#module functions.py def foo(input, new_val):input = new_val#module main.py input = 5 functions.foo(input, 10)print inputI thought input would now be 10. Why is this not the cas…

Python: -mno -cygwin

im trying to learn a lot of python on windows and that includes installing several packages, however everytime i invoke python setup.py install i have a problem with -mno -cygwin for gcc. ive have rea…

Django Sites Framework initial setup

Im comfortable with fairly one-dimensional Django implementations, but now trying to understand the multi-sites-with-shared-stuff process. Ive read through the Django Sites Framework and many posts o…