def main(): print('carga de archivo') print('................') print('\n') dirname = os.path.dirname(__file__) filename = os.path.join(dirname, '../data/FormatoDeAlmacenamiento1.csv') df = pd.read_csv(filename, sep=';', header=None, na_values=" NaN") #print (df) hora = df[0].str.extract('((?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d)') #print (hora) #remplazo los na por cero df2 = pd.DataFrame() df2 = df2.fillna(0) df2[0] = df[0].str.extract('((?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d)') df2[1] = df[1] #print(df2) print("se agrupa por minutos") df2[0] = pd.DatetimeIndex(df2[0]) df2.set_index(keys=0, inplace=True) ini = datetime.time(00, 18, 0) fin = datetime.time(23, 59, 0) df3 = df2[[1]].between_time(ini, fin) df3 = df3.groupby([1])[[1]].count() print(df3)
def get_heatmap_temp_min(self): filtros_temperaturas = self.data_access.get_filtros_clima() def hora_hora(x): return int(x[0:2]) tem = self.data_access.get_df_temperatura() tem['Fecha'] = pd.to_datetime(tem['Fecha']) tem['Day_week'] = tem['Fecha'].dt.day_name() tem["Hora_single"] = tem["Hora"].apply(hora_hora) df_tem_min_hora = tem.groupby(['Fecha', 'Day_week', 'Hora_single']).min() estacion = filtros_temperaturas['estacion'] filtro = filtros_temperaturas['rango_clima'] df_tem_min_hora_finca = df_tem_min_hora.filter([estacion]) dist = df_tem_min_hora_finca.reset_index(level=[0, 1, 2]) dist['Month_number'] = dist['Fecha'].dt.month dist['Month'] = dist['Fecha'].dt.strftime('%B') dist['year'] = pd.DatetimeIndex(dist['Fecha']).year dist['day'] = dist['Fecha'].dt.day dist = dist.groupby([filtro, 'Hora_single'])[estacion].mean() df = dist.to_frame() dist_df = df.reset_index(level=[0, 1]) dist_df['x'] = dist_df[filtro] dist_df['z'] = dist_df[estacion] return dist_df
def historicalData(self, idx: int, b: BarData): self.cacheEnrichTimeout = time.time() + 60 # super().historicalData(idx, b) s = Series(data=[b.average], index=pandas.DatetimeIndex([b.date], dtype='datetime64[ns]', freq='D')) self.id2hist[idx]['data'] = self.id2hist[idx]['data'].append(s)
def contractDetails(self, idx: int, cd: ContractDetails): c = cd.contract sid, sym = c.conId, c.symbol s = Series(data=[], dtype=float, index=pandas.DatetimeIndex([], dtype='datetime64[ns]', freq='D')) self.id2hist[sid] = {'symbol': sym, 'data': s} self.reqHistoricalData(sid, c, self.timeStr, self.duration, self.barSize, self.type, 0, 1, False, [])
from data import data from pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') #This is a program used to query incoming stock data. # get the data from the excel file df = pd.read_excel('companyData.xlsx') # Change the data frame to be indexed by date df = df.set_index(pd.DatetimeIndex(df['date'].values)) # make a graph plt.figure(figsize=(14.0, 8.0)) plt.plot(df['4. close'], label='close') plt.title('Daily close price') plt.xticks(rotation=45) plt.xlabel('Date') plt.ylabel('Price $') # plt.show() # Calculate MACD and signal line indicators # Calculate the short term exponential moving average (EMA) short_EMA = df['4. close'].ewm(span=12, adjust=False).mean() # Calculate long term exponential moving average long_EMA = df['4. close'].ewm(span=26, adjust=False).mean() # calculate MACD line MACD = short_EMA - long_EMA # create signal line signal = MACD.ewm(span=9, adjust=False).mean() plt.figure(figsize=(12.5, 5.0))
return '-' from pandas import pandas as pd # from datetime import datetime as dt # from random import random as rand # from numpy.random import randn print '1/8 - Loading data' df = pd.read_csv('dataset.csv', header=None, parse_dates=[1], names=['UserID', 'DateTime', 'AntennaID'], infer_datetime_format=True) temp = pd.DatetimeIndex(df['DateTime']) df['Date'] = temp.date df['Time'] = temp.time """ # Filtering User df_user_1 = df.groupby(['UserID'], sort=False).agg({"Date": lambda x: x.nunique()}) df_user_2 = df_user_1[df_user_1['Date'] > 2] df_user_3 = df_user_2['Date'] df_user_3.to_csv('output_df_user.csv') df_user_list = pd.read_csv('output_df_user.csv', header=None, names=['UserID', 'DaySeen']) df['ActiveUser'] = df['UserID'].isin(df_user_list['UserID']) """ df['DayData'] = df['DateTime'].apply(classify_weekday)