I am trying to put together a big dataframe wih dates, average sentiment scores (from Twitter), and closing stock price.
Here is what I have so far.
#imports
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import re
import urllib3
import requests
import datetime
#mydates dataframe that just has the dates from my desired range. Shape is 2008 rows x 1 column
date1='2014-01-01'
date2='2019-07-01'
mydates =pd.date_range(date1,date2).tolist()
newdf =pd.DataFrame({'Date':mydates})
#df with the average daily sentiment scores. Large dataset with 500 rows.
#This currently skips dates that didn't have tweets.I want to include those dates but have sentiment equal 0.
Date Score
2014-01-13 0.01
2014-01-14 0.035
2014-01-15 0.453
2014-01-20 0.06474
#ts dataframe of dates and stock prices. Shape is 1381 rows x 1 column
Date Adj Close
2014-01-13 44.8
2014-01-14 45.3
2014-01-15 45.8
2014-01-16 46.5
2014-01-17 46.5
2014-01-21 46.7
Desired output
Date Score Close Price
2014-01-13 0.01 44.8
2014-01-14 0.035 45.3
2014-01-15 0.453 45.8
2014-01-16 0.0 46.5
2014-01-17 0.0 46.5
2014-01-18 0.0 46.5
2014-01-19 0.0 46.5
2014-01-20 0.06474 46.5
My plan is to then save this dataset as a csv.
Issues I've run into: Df and ts are NOT the same size. I'd need to go through ts to make all the weekend close prices the same as Friday. How do I do that? Not knowing how to write a loop that can assign the score for a date in one dataframe to a column in another dataframe.
I use pandas-3.
