gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Can you give me pandas's code, to find the number of row in dataset that have a colum…
- User
Can you give me pandas's code, to find the number of row in dataset that have a colum with date before 1900 ?
- Assistant
Certainly! Here's an example code that uses pandas to find the number of rows in a dataset where a specific column contains a date before 1900:
import pandas as pd # Assuming your dataset is in a CSV file called 'data.csv' df = pd.read_csv('data.csv') # Assuming the column containing dates is named 'date_column' # Make sure it is already in datetime format, otherwise parse it using pd.to_datetime() # Create a boolean mask to check if each date is before 1900 mask = df['date_column'] < pd.Timestamp('1900-01-01') # Count the number of rows where the condition is True num_rows_before_1900 = df[mask].shape[0] print(f"Number of rows with dates before 1900: {num_rows_before_1900}")Make sure to replace
'data.csv'with your actual dataset file name, and'date_column'with the name of the column that contains the dates in your dataset.