get columns based on dtype pandas
>>df.select_dtypes(include='object').columns
Index(['C', 'D'], dtype='object')
get columns based on dtype pandas
>>df.select_dtypes(include='object').columns
Index(['C', 'D'], dtype='object')
validating columns in pandas on the basis of dtypes
import pandas as pd
import pandera as pa
df = pd.DataFrame({
"column1": [1, 2, 3],
"column2": ["a", "b", "c"],
})
column1_schema = pa.Column(pa.Int, name="column1")
column2_schema = pa.Column(pa.String, name="column2")
# pass the dataframe as an argument to the Column object callable
df = column1_schema(df)
validated_df = column2_schema(df)
# or explicitly use the validate method
df = column1_schema.validate(df)
validated_df = column2_schema.validate(df)
# use the DataFrame.pipe method to validate two columns
validated_df = df.pipe(column1_schema).pipe(column2_schema)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us