我正在使用this schema,并在关键部分注意到以下内容:
df['UniqueId'] = range(0, 14571, 1)
df['StartDate'] = pd.to_datetime(df['StartDate'])
df['EndDate'] = pd.to_datetime(df['EndDate'])
#converts dates to dateTime
df2 = df.loc[df.duplicated(subset=['DeviceId'],keep=False)]
#Returns list of trips with repeated deviceid
DeviceIds = df2['DeviceId'].tolist()
DeviceIds = list(set(DeviceIds))
df3 = pd.DataFrame(columns = ['UniqueId','Difference'])
for ID in DeviceIds: #creats mini dataframes for every DeviceId
temp = df2.loc[df2['DeviceId'] == ID]
temp.sort_values(by='StartDate')
temp['PreviousEnd'] = temp['EndDate'].shift(periods=1)
temp['Difference'] = temp['StartDate'] - temp['PreviousEnd']
temp['Difference'] = [1 if x < pd.Timedelta('24H')
else 0 for x in temp['Difference']]
temp = temp[['UniqueId','Difference']]
df3 = pd.concat([df3,temp])
df.set_index('UniqueId').join(df3.set_index('UniqueId'),how='left')
这两个键都指的是这一部分:
<xs:key name="KeyAnalysisType">
<xs:selector xpath="MasterFiles/AnalysisTypeTable/AnalysisTypeTableEntry"/>
<xs:field xpath="AnalysisType"/>
</xs:key>
<xs:key name="KeyAnalysisID">
<xs:selector xpath="MasterFiles/AnalysisTypeTable/AnalysisTypeTableEntry"/>
<xs:field xpath="AnalysisID"/>
</xs:key>
这个双键定义是否与两个字段的复合键选择相同? E.g。
<xs:element name="AnalysisTypeTable" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="AnalysisTypeTableEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AnalysisType" type="FAIAcodeType">
<xs:annotation>
<xs:documentation>Analysis type identifier: e.g. CC (for Cost Center), DEP (for department), etc.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="AnalysisTypeDescription" type="FAIAlongtextType">
<xs:annotation>
<xs:documentation>Description of the AnalysisType, e.g. "Cost Center"</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="AnalysisID" type="FAIAmiddle1textType">
<xs:annotation>
<xs:documentation>Analysis ID: e.g. 1200-HDOF-TR (for cost center treasury in the headoffice) </xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="AnalysisIDDescription" type="FAIAlongtextType">
<xs:annotation>
<xs:documentation>Description of the AnalysisID: e.g. "Headoffice-Treasury".</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
答案 0 :(得分:1)
双键定义在一个重要方面有所不同 从复合键。拿这个示例文档:
<root>
<item key1="A" key2="a"/>
<item key1="B" key2="b"/>
<reference ref1="A" ref2="a"/>
<reference ref1="B" ref2="b"/>
</root>
让我们为key1
和key2
节点定义单独的密钥:
<xs:key name="Key1">
<xs:selector xpath="item"/>
<xs:field xpath="@key1"/>
</xs:key>
<xs:key name="Key2">
<xs:selector xpath="item"/>
<xs:field xpath="@key2"/>
</xs:key>
<xs:keyref name="Keyref1" refer="Key1">
<xs:selector xpath="reference"/>
<xs:field xpath="@ref1"/>
</xs:keyref>
<xs:keyref name="Keyref2" refer="Key2">
<xs:selector xpath="reference"/>
<xs:field xpath="@ref2"/>
</xs:keyref>
在这种情况下,键是分开匹配的,
彼此不了解。因此,允许<reference>
元素引用不同<item>
个元素的键,这些元素可能是也可能不是;
<root>
<item key1="A" key2="a"/>
<item key1="B" key2="b"/>
<reference ref1="A" ref2="b"/> <!-- Mix of "A" and "b" -->
<reference ref1="B" ref2="a"/> <!-- Mix of "B" and "a" -->
</root>
另一方面,如果使用复合密钥,则使用上述文档
会无效的。因为那时键被匹配为一个组,
并且<reference>
元素必须引用单个<item>
元素
匹配两个键(如第一个示例中所示):
<xs:key name="Key12">
<xs:selector xpath="item"/>
<!-- Both fields belong to the same <item> element -->
<xs:field xpath="@key1"/>
<xs:field xpath="@key2"/>
</xs:key>
<xs:keyref name="Keyref12" refer="Key12">
<xs:selector xpath="reference"/>
<!-- Both fields belong to the same <reference> element -->
<xs:field xpath="@ref1"/>
<xs:field xpath="@ref2"/>
</xs:keyref>
答案 1 :(得分:-1)
我不保证它在所有情况下都是绝对等效的,例如:当其中一个字段存在而另一个字段不存在时。但在正常情况下,两个字段都存在,我认为这两个结构是等价的。