-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsv_mysql.py
More file actions
50 lines (33 loc) · 1.4 KB
/
csv_mysql.py
File metadata and controls
50 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pandas as pd
import os
from sqlalchemy import create_engine
db_pass = os.environ.get('rich_m_pass')
engine = create_engine('mysql+pymysql://rich_m:' + db_pass + '@localhost:3306/sa_db')
def sent_a():
"""adds sentiment score data using a pandas dataframe converted from a local csv"""
with open('NewsAPI/sentiment.csv', 'r') as file:
df = pd.read_csv(file)
df.to_sql(name='sent_a', con=engine, index=False, index_label='id', if_exists='replace')
def headlines():
"""adds headline data using a pandas dataframe converted from a local csv"""
with open('news_api_20200514/headlines2.csv', 'r') as file:
df = pd.read_csv(file)
df.to_sql(name="h_lines", con=engine, index=False, index_label='id', if_exists='replace')
def news():
with open('news_api_20200514/news.csv', 'r') as file:
df = pd.read_csv(file)
df.to_sql("news", con=engine, index=False, index_label='id', if_exists='replace')
def yfin():
with open('yfinance.csv', 'r') as file:
df = pd.read_csv(file)
df.to_sql(name="yfin", con=engine, index=False, index_label='id', if_exists='replace')
def twitter():
with open('Twitter/twitter_request_tsla.csv', 'r') as file:
df = pd.read_csv(file)
df.to_sql(name="twitter", con=engine, index=False, index_label='id', if_exists='replace')
if __name__ == '__main__':
sent_a()
headlines()
news()
yfin()
twitter()