Python Forum
pandas restricting csv read to certain rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas restricting csv read to certain rows
#3
Hi Dead_Eye,

Many thanks for your reply.
I tried what you suggested but even though there are years in range, nothing gets extracted.

    mask =(pd.DatetimeIndex(train_df['ticket_issued_date']).year > 2012) & (pd.DatetimeIndex(train_df['ticket_issued_date']).year < 2016)
    print(train_df[mask]) # is empty

    train_df['yearcolumn'] = pd.DatetimeIndex(train_df['ticket_issued_date']).year
    print(train_df['yearcolumn'].unique())
    #output [2004 2005 2006 2007 1938 1963 1988 2008 2009 2010 2011]
Reply


Messages In This Thread
RE: pandas restricting csv read to certain rows - by metalray - Dec-07-2017, 10:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas read csv file in 'date/time' chunks MorganSamage 4 1,717 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
Smile How to further boost the data read write speed using pandas tjk9501 1 1,275 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Pandas Dataframe Filtering based on rows mvdlm 0 1,449 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  [Pandas] Help with finding only non-matching rows LowEnd 3 3,585 Nov-12-2021, 02:34 PM
Last Post: jefsummers
  Can't read text file with pandas zinho 6 12,152 May-24-2020, 06:13 AM
Last Post: azajali43
  Read json array data by pandas vipinct 0 1,960 Apr-13-2020, 02:24 PM
Last Post: vipinct
  pandas head() not reading all rows naab 0 1,819 Apr-07-2020, 01:06 PM
Last Post: naab
  getting trailing zeros with 1 during pandas read fullstop 1 3,621 Jan-05-2020, 04:01 PM
Last Post: ichabod801
  How to add a few empty rows into a pandas dataframe python_newbie09 2 16,350 Sep-20-2019, 08:52 AM
Last Post: python_newbie09
  Read Nested JSON with pandas.io.json palo173 4 9,603 Apr-29-2019, 01:25 PM
Last Post: palo173

Forum Jump:

User Panel Messages

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