I am working on a fake news detector, I want to check if the content of the news headline [TITLE] is inside the content of the news [TEXT]. If the result is True
it should return 1 and if it’s False
it should return 0. the return value forms a new column
This work is for a research publication. I have tried using SVM for this
JavaScript
x
6
1
import pandas as pd
2
news1= pd.read_csv('dataset/id_title_author_text_label.csv')
3
news1.head()
4
news1['News_column'] = news1[news1['TITLE'].str.contain in news1['TEXT']]
5
news1['News_column'] = news1['News_column'].map({True: 'Yes', False: 'No'})
6
I expect the output to look like this:
JavaScript
1
8
1
News_column
2
1
3
1
4
0
5
0
6
0
7
1
8
Advertisement
Answer
You can use an apply on each row of your dataframe like this :
news1['News_column'] = news1.apply(lambda x: 1 if x['TITLE'] in x['TEXT'] else 0, axis=1)
Should return the expected result.