如何在Python中使用BCE/CE后缀解析年份?
我试图用Python呈现CE/BCE日期图。我试着用如何在Python中使用BCE/CE后缀解析年份?,python,date,Python,Date,我试图用Python呈现CE/BCE日期图。我试着用datetime、dateutil和astropy来绘制图表,但没有成功。 当我使用datetime和astropy时,我发现它不支持CE/BCE年。 使用dateutil我尝试: from dateutil.parser import * bc = parse(u'2000BCE') 但它有一个错误: ValueError: Unknown string format 如何用python呈现CE/BCE年数?是否有支持BCE/CE年的
datetime
、dateutil
和astropy
来绘制图表,但没有成功。
当我使用datetime
和astropy
时,我发现它不支持CE/BCE年。
使用dateutil
我尝试:
from dateutil.parser import *
bc = parse(u'2000BCE')
但它有一个错误:
ValueError: Unknown string format
如何用python呈现CE/BCE年数?是否有支持BCE/CE年的库
我使用的数据是字符串列表,如下所示:
0 CE
1000 CE
1007 CE
104 BCE
10450 BCE
1050 BCE
1050 BCE
1050 BCE
我没有在python中找到支持BCE/CE日期的包,因此我进行了以下解释:
#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")
大家好,欢迎!你可以先发布你已经拥有的代码中不起作用的特定部分。你说的“现在”和“图表”是什么意思?你到底尝试了什么(a会有帮助)以及它是如何失败的?当我使用datetime和astropy时,我发现它不支持BC/BCE年。对于dateutil,我尝试了:从dateutil.parser导入*parse(b)bc=parse(u'2000BC'),但它有一个错误值error:Unknown string format
0
不是有效年份…@Attie据我所知-BCE和CE遵循的规则与非常有趣的方法相同。