Python Forum
Pandas and Date: problem with operator.How to resolve
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas and Date: problem with operator.How to resolve
#6
(May-13-2019, 04:05 PM)frame Wrote: The conversion work, but applying "df.where" to filter df["Date"]>"30/11/2014"", the result does not change. Is valid the operator > or i do to use only operator ==?
The code for @Yoriz should work,is that what you have problem with or are doing something else?
Doing myfilter = df["Date"] == "30/11/2014" it will only drop.
Output:
Conc. Date I II 2 8928.0 30/11/2014 3.0 15.0
Test of code:
>>> import pandas as pd

>>> df = pd.read_clipboard()
>>> df['Date'] = pd.to_datetime(df['Date'])
>>> df
   Conc.       Date  I  II
0   8926 2014-11-18  1  22
1   8927 2014-11-20  2  33
2   8928 2014-11-30  3  15
3   8929 2014-12-18  4  80
4   8930 2014-12-28  8  60
5   8931 2014-12-31  9  12

>>> myfilter = df["Date"] > "30/11/2014"
>>> df = df.where(myfilter ,axis=1).dropna()
>>> df['Date'] = df['Date'].dt.strftime('%d/%m/%Y')
>>> df
    Conc.        Date    I    II
3  8929.0  18/12/2014  4.0  80.0
4  8930.0  28/12/2014  8.0  60.0
5  8931.0  31/12/2014  9.0  12.0
Reply


Messages In This Thread
RE: Pandas and Date: problem with operator.How to resolve - by snippsat - May-13-2019, 04:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas read csv file in 'date/time' chunks MorganSamage 4 1,755 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
  Does a pandas have a date without a time? AlekseyPython 6 4,993 Feb-10-2021, 09:24 AM
Last Post: Naheed
  problem with opening csv file in pandas saratha 2 2,582 Jul-21-2020, 10:55 AM
Last Post: saratha
  replace nan values by mean group by date.year, date.month wissam1974 5 8,546 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Obtaining Correct Date In Pandas DataFrame eddywinch82 14 6,077 Feb-17-2020, 11:45 AM
Last Post: eddywinch82
  Problem with date type (object to datetime) karlito 6 3,679 Oct-16-2019, 08:07 AM
Last Post: karlito
  Trying to Pass date to pandas search from input prompt curranjohn46 1 2,138 Oct-10-2019, 10:01 AM
Last Post: curranjohn46
  Need help passing date to pandas query curranjohn46 1 5,512 Oct-10-2019, 09:59 AM
Last Post: curranjohn46
  How to resolve scipy differences? Oliver 2 3,978 Oct-08-2019, 08:40 PM
Last Post: Oliver
  Pandas converting date to epoch randor 2 3,964 Jul-16-2019, 02:41 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020