True News and Fake News
We will now start working on our project. The final goal of our analysis is to predict whether the given news is fake or true. You will handle text data and build ML (Machine Learning) algorithms.
Tarefa
Swipe to start coding
- Read the CSV files containing fake news and true news into their respective DataFrames.
- Set the values of the target column
'class'
to0
for thefake_news
DataFrame and to1
for thetrue_news
DataFrame. - Use the appropriate function to merge these two DataFrames.
- Display the first 5 rows of the resulting DataFrame using the appropriate method.
Solução
import pandas as pd
# Read the CSV files into DataFrames
fake_news = pd.read_csv(
'https://content-media-cdn.codefinity.com/projects/ef7b5b8f-99b5-4289-8380-5a7ba3adedc5/Fake.csv')
true_news = pd.read_csv(
'https://content-media-cdn.codefinity.com/projects/ef7b5b8f-99b5-4289-8380-5a7ba3adedc5/True.csv')
# Set the values of the target column
fake_news['class'] = 0
true_news['class'] = 1
# Merge two DataFrames
news_merged = pd.concat([fake_news, true_news], axis=0).reset_index(drop=True)
# Display the first 5 rows of news_merged
news_merged.head()
Mark tasks as Completed
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 2
AVAILABLE TO ULTIMATE ONLY