2

I have a big csv file(contains 21 column). The file contains last few days data of user. I want to filter this file based on column values. The column is "Logout Time". Column value is like "Mon Jun 15 11:12:12 EST 2015". I want to make a seperate csv file for those records whose "Logout Time" is "Mon Jun 15" irrespective of the time. I tried to do this using pandas. To get those records I tried this:

df[df['Logout Time'].str.contains("Mon Jun 15")]

this gives me error as:

ValueError : cannot index with vector containing NA / NaN values

I tried this one also:

df[df['Logout Time'].str.contains("Mon Jun 15") == True]

this doesnt filter the results. it gave me whole records of original csv.

6
  • Can you post the output from df.info() what is log out time? is a str or a datetime dtype? Your first attempt should have worked unless you had no matches, what does df['Logout Time'].str.contains("Mon Jun 15") show? Commented Jun 24, 2015 at 13:52
  • I see dtype for that column as object, neither str nor datetime. df['Logout Time'].str.contains("Mon Jun 15") shows Value error ValueError : cannot index with vector containing NA / NaN values Commented Jun 24, 2015 at 13:58
  • So does df['Logout Time'].dropna().str.contains("Mon Jun 15") return anything? Commented Jun 24, 2015 at 14:18
  • yes..It gives me the boolean output for the match (True/False) Commented Jun 24, 2015 at 14:23
  • So does df[df['Logout Time'].dropna().str.contains("Mon Jun 15")] work? Commented Jun 24, 2015 at 14:24

1 Answer 1

2

Your problem is that your data contains NaN values so you need to drop them using dropna first:

df[df['Logout Time'].dropna().str.contains("Mon Jun 15")]

so the above should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.