本文整理汇总了Python中schema.Schema.fromDF方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.fromDF方法的具体用法?Python Schema.fromDF怎么用?Python Schema.fromDF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.fromDF方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import fromDF [as 别名]
def __init__(self,name,schema=Schema([]),filename="",dataframe=pd.DataFrame(),check=True):
self.name = name #name of the relation
self.schema = schema #schema of relation
self.filename = filename #file relation comes from
self.df = not dataframe.empty
self.dataframe = dataframe
if not dataframe.empty:
self.schema = Schema.fromDF(dataframe)
if check:
if dataframe.empty and filename == "":
raise Exception("Relation "+self.name+" needs a filename (either a file or dataframe).")
示例2: __init__
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import fromDF [as 别名]
def __init__(self,name,schema=Schema([]),filename="",dataframe=pd.DataFrame(),check=True,attribute_names=[],annotation_names=[]):
# Replace int64 with int32. TODO: Make int64 work?
int64_cols = [
col for col, dtype in dataframe.dtypes.to_dict().items()
if dtype == "int64"
]
dataframe[int64_cols] = dataframe[int64_cols].astype(pd.np.int32)
self.name = name #name of the relation
self.schema = schema #schema of relation
self.filename = filename #file relation comes from
self.df = not dataframe.empty
self.dataframe = dataframe
if not dataframe.empty:
self.schema = Schema.fromDF(dataframe,attribute_names,annotation_names)
if check:
if dataframe.empty and filename == "":
raise Exception("Relation "+self.name+" needs a filename (either a file or dataframe).")