I am trying to filter out the dataframe that contains a list of product. However, I am getting the error 'dataframe' object has no attribute 'str' whenever I run the code.
Here is the line of code:
include_clique = log_df.loc[log_df['Product'].str.contains("Product A")]
Product is an object datatype.
import pandas as pd
import numpy as np
data = pd.read_csv("FILE.csv", header = None)
headerName = ["DRID", "Product", "M24", "M23", "M22", "M21"]
data.columns = [headerName]
log_df = np.log(1 + data[["M24", "M23", "M22", "M21"]])
copy = data[["DRID", "Product"]].copy()
log_df = copy.join(log_df)
include_clique = log_df.loc[log_df['Product'].str.contains("Product A")]
Here is the head:
ID PRODUCT M24 M23 M22 M21
0 123421 A 0.000000 0.000000 1.098612 0.0
1 141840 A 0.693147 1.098612 0.000000 0.0
2 212006 A 0.693147 0.000000 0.000000 0.0
3 216097 A 1.098612 0.000000 0.000000 0.0
4 219517 A 1.098612 0.693147 1.098612 0.0
log_df.strsomewhere (instead oflog_df['Product'].str)? Or maybe you have duplicated indexes with this nameProduct(e.g. two columns with same name) ?type(log_df['Product'])?