Last active
January 18, 2024 10:50
-
-
Save SnowyPainter/86d04281e41335eb780ac349169a3b32 to your computer and use it in GitHub Desktop.
3개 이상 merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
files = ["nvda.csv", "vix.csv", "eur.csv"] | |
def open_df(fn): | |
df = pd.read_csv(fn) | |
df.drop(["Vol.","Change %","Open","Low","High"], axis=1, inplace=True) | |
df["Price"] = df["Price"].astype(float) | |
df['Date'] = pd.to_datetime(df['Date'], format='%m/%d/%Y') | |
df = df.sort_values(by='Date') | |
df.set_index('Date', inplace=True) | |
return df | |
def inverse_min_max_scaling(normalized_data, min_value, max_value): | |
original_data = normalized_data * (max_value - min_value) + min_value | |
return original_data | |
def normalize_all_columns(df): | |
cols = ["Price"] | |
for col in cols: | |
df[col] = (df[col]-df[col].min())/(df[col].max()-df[col].min()) | |
return df | |
def df(files): | |
dfs = [] | |
merged = "" | |
for fn in files: | |
name = fn.split('.')[0] | |
df = open_df(fn) | |
df = normalize_all_columns(df) | |
df.rename(columns={'Price': name+'_Price'}, inplace=True) | |
dfs.append(df) | |
if(len(dfs) == 1): | |
merged = df | |
if(len(dfs) > 1): | |
merged = merged.merge(df, on='Date') | |
return merged | |
def get_df(): | |
return df(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment