def build_dataframe(self):
if not self.values.exists():
return pd.DataFrame()
# Am I really a programmer or just a lego assembler?
# Pandas makes my life at least 20 times easier.
df = pd.DataFrame.from_records(self.values, index=self.index_column)
# make the columns and labels prettier
if self.rename_columns:
df = df.rename(columns=self.column_mapping)
df.index.name = TIME_COLUMN_NAME
try:
df.index = df.index.tz_convert(self.user.pytz_timezone)
except AttributeError:
# if attribute-error means the index is just a regular Index and
# that only dates (and not time) was passed
df.index = pd.DatetimeIndex(df.index, tz=self.user.pytz_timezone)
# cast it as numerics if possible, otherwise if we're dealing with strings, ignore
df = df.apply(pd.to_numeric, errors='ignore')
return df
评论列表
文章目录