本文整理匯總了Python中pandas.core.frame.DataFrame.from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python DataFrame.from_dict方法的具體用法?Python DataFrame.from_dict怎麽用?Python DataFrame.from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.frame.DataFrame
的用法示例。
在下文中一共展示了DataFrame.from_dict方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_describe
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import from_dict [as 別名]
def test_describe(self):
# string type
desc = self.factor.describe()
expected = DataFrame.from_dict(
dict(counts=[3, 2, 3], freqs=[3 / 8.0, 2 / 8.0, 3 / 8.0], levels=["a", "b", "c"])
).set_index("levels")
tm.assert_frame_equal(desc, expected)
# check an integer one
desc = Categorical([1, 2, 3, 1, 2, 3, 3, 2, 1, 1, 1]).describe()
expected = DataFrame.from_dict(
dict(counts=[5, 3, 3], freqs=[5 / 11.0, 3 / 11.0, 3 / 11.0], levels=[1, 2, 3])
).set_index("levels")
tm.assert_frame_equal(desc, expected)
示例2: describe
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import from_dict [as 別名]
def describe(self):
"""
Returns a dataframe with frequency and counts by level.
"""
# Hack?
from pandas.core.frame import DataFrame
grouped = DataFrame(self.labels).groupby(0)
counts = grouped.count().values.squeeze()
freqs = counts / float(counts.sum())
return DataFrame.from_dict(dict(counts=counts, freqs=freqs, levels=self.levels)).set_index("levels")
示例3: dataframe_from_universe_dict
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import from_dict [as 別名]
def dataframe_from_universe_dict(universe_dict):
timestamps = []
outer_frames = []
for timestamp, hl_ticker_dict in universe_dict.iteritems():
timestamps.append(timestamp)
inner_frames = []
hl_tickers = []
for hl_ticker, low_level_ticker_dict in hl_ticker_dict.iteritems():
hl_tickers.append(hl_ticker)
inner_frames.append(DataFrame.from_dict(low_level_ticker_dict, orient='index'))
hl_ticker_frame = pd.concat(inner_frames, keys=hl_tickers)
outer_frames.append(hl_ticker_frame)
universe_df = pd.concat(outer_frames, keys=timestamps)
return universe_df
示例4: tee
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import from_dict [as 別名]
from pandas.io.pytables import HDFStore
from makstat.zavod import iter_contextual_atom_data, get_metadata
stream = (line.decode('cp1251').strip().encode('utf-8')
for line in stdin)
# tee the stream to get the metadata for title
stream, stream_2 = tee(stream)
title = get_metadata(stream_2)['TITLE']
df = DataFrame()
for cur_data in iter_contextual_atom_data(stream):
current = DataFrame.from_dict([cur_data])
df = df.append(current, ignore_index=False)
index_cols = list(df.columns.values)
index_cols.remove('value')
df.set_index(index_cols, inplace=True)
df.columns = [title]
# create removable temp file for use with HDFStore
tmpfile = NamedTemporaryFile().name
store = HDFStore(tmpfile)
store['default'] = df
store.close()
# put h5 file to stdout