0

I want to select rows that match a condition and write to a new csv file. Here's my code and some sample data and i'm sure the type of 'id' is string. It only gives me the header row in the new file.

enter image description here

import pandas as pd

df = pd.read_csv("data.csv")
df[(df['id'] == '48')].to_csv("out.csv", index=False)

I'm wondering where the problem is. Thanks for the help!

1
  • 1
    Add sample data of df dataframe Commented Aug 7, 2020 at 6:06

1 Answer 1

1

It might be happening because id would be a numerical value.

import pandas as pd

df = pd.read_csv("data.csv")
df[(df['id'] == 48)].to_csv("out.csv", index=False)
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.