2017-06-23 25 views
0

我想在Python中顯示CE/BCE日期圖。我試圖使用datetimedateutilastropy作爲圖表,但沒有奏效。 當我使用datetimeastropy時,我看到它沒有CE/BCE年的支持。 隨着dateutil我想:如何在Python中用BCE/CE後綴解析年份?

from dateutil.parser import * 
bc = parse(u'2000BCE') 

但它有一個錯誤:

ValueError: Unknown string format 

我可以如何呈現CE/BCE年的蟒蛇?是否有任何圖書館支持BCE/CE年?

我使用的數據是一個字符串列表,看起來像:

0 CE 
1000 CE 
1007 CE 
104 BCE 
10450 BCE 
1050 BCE 
1050 BCE 
1050 BCE 
+0

你好,歡迎光臨!你可以開始發佈你已有的代碼的特定部分,這是行不通的。 –

+0

你是什麼意思的「現在」和什麼「圖」?你究竟做了什麼([mcve]會有幫助),它是如何失敗的? –

+0

當我使用datetime和astropy時,我看到它不支持BC/BCE年。隨着dateutil我想:從dateutil.parser進口* 解析(二) BC =解析(u'2000BC'),但它有一個錯誤ValueError異常:未知的字符串格式 –

回答

0

我沒有發現支持蟒蛇BCE/CE日期的packege所以我做了以下interpulation:

#looks for values containing BCE  
BCE = [s for s in yearsList if "BCE" in s] 
#removes BCE string 
BCE = [x.strip(' BCE') for x in BCE] 
#defines them as integers 
BCE = list(map(int, BCE)) 
#add minus sign to BCE years 
BCE = [ -x for x in BCE] 

CE = [s for s in yearsList if " CE" in s] 
CE = [x.strip(' CE') for x in CE] 
CE = list(map(int, CE)) 

#merges the BCE and the CE integers to one list 
mergedlist = BCE + CE 

#plot the list 
sns.distplot(mergedlist) 
plt.xlabel("Year")