I apologize for the neophyte question, but I'm having a hard time figuring out Pandas' data frames. I have one data frame with something like
df_index:
Product Title
100000 Sample main product
200000 Non-consecutive main sample
I have another data frame with a more detailed list of the products with formats, like
df_details:
Product Title
100000 Sample main product
100000-Format-English Sample product details
100000-Format-Spanish Sample product details
100000-Format-French Sample product details
110000 Another sample main product
110000-Format-English Another sample details
110000-Format-Spanish Another sample details
120000 Yet another sample main product
120000-Format-English Yet another sample details
120000-Format-Spanish Yet another sample details
...
200000 Non-consecutive main sample
200000-Format-English Non-consecutive sample details
200000-Format-Spanish Non-consecutive sample details
I want to create a new data frame based on df_details, but only for the products that appear in df_index. Ideally, it would look something like:
new_df:
Product Title
100000 Sample main product
100000-Format-English Sample product details
100000-Format-Spanish Sample product details
100000-Format-French Sample product details
200000 Non-consecutive main sample
200000-Format-English Non-consecutive sample details
200000-Format-Spanish Non-consecutive sample details
Here's what I've tried so far:
new_df = df_details[df_details['Product'][0:5] == df_index['Product'][0:5]]
That gives me a error:
ValueError: Can only compare identically-labeled Series objects
I've also tried
new_df = pd.merge(df_index, df_details,
left_on=['Product'[0:5]], right_index=True, how='left')
Which does give me a resulting data set, but not the kind I want—it doesn't include the details rows with the format information.