3 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
使用是pd.Timestamp因?yàn)槲覀兊淖值滏I類型pd.Timestamp不是str.
import pandas as pd
d[pd.Timestamp('2020-06-30 00:00:00')]["intangibleAssets"]
295

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊
下面的函數(shù)是通用的,可以應(yīng)用于任意數(shù)量的字典。
獲取鑰匙:
def matchingKeys(dictionary, searchString): return [key for key,val in dictionary if searchString in val]
要獲取值:
def matchingValues(dictionary, searchString): return [val for key,val in dictionary if searchString in val]
要同時(shí)獲得:
def matchingElements(dictionary, searchString): return {key:val for key,val in dictionary if searchString in val}

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊
由于您使用的是 pandas,因此您可以轉(zhuǎn)換為數(shù)據(jù)框并使用loc或.iloc傳遞您感興趣的行和列:
與.loc:
d = {'2020-06-30 00:00:00': {'intangibleAssets': 295, 'capitalSurplus': 415},'2020-03-30 00:00:00': {'intangibleAssets': 400, 'capitalSurplus': 50}}
df = pd.DataFrame(d).loc['intangibleAssets','2020-06-30 00:00:00']
df
295
或iloc:
d = {'2020-06-30 00:00:00': {'intangibleAssets': 295, 'capitalSurplus': 415},'2020-03-30 00:00:00': {'intangibleAssets': 400, 'capitalSurplus': 50}}
df = pd.DataFrame(d).iloc[0,0]
df
295
添加回答
舉報(bào)