bugfix(vol10): 修复to_datetime无法正确转换数值日期表示的问题

This commit is contained in:
100gle
2022-07-17 10:20:29 +08:00
parent 5cf5991d2d
commit e47b2e5fe9

View File

@@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 148,
"execution_count": 1,
"metadata": {
"collapsed": true
},
@@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 149,
"execution_count": 2,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -63,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 150,
"execution_count": 3,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -105,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 151,
"execution_count": 4,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -124,7 +124,7 @@
"Name: numbers, dtype: int64"
]
},
"execution_count": 151,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -143,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 152,
"execution_count": 5,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -157,7 +157,7 @@
"RangeIndex(start=0, stop=100, step=1)"
]
},
"execution_count": 152,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -168,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 153,
"execution_count": 6,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -190,7 +190,7 @@
},
{
"cell_type": "code",
"execution_count": 154,
"execution_count": 7,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -204,7 +204,7 @@
"dtype('int64')"
]
},
"execution_count": 154,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -215,7 +215,7 @@
},
{
"cell_type": "code",
"execution_count": 155,
"execution_count": 8,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -229,7 +229,7 @@
"(100,)"
]
},
"execution_count": 155,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -240,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 156,
"execution_count": 9,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -254,7 +254,7 @@
"100"
]
},
"execution_count": 156,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -265,7 +265,7 @@
},
{
"cell_type": "code",
"execution_count": 157,
"execution_count": 10,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -279,7 +279,7 @@
"'numbers'"
]
},
"execution_count": 157,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -290,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 158,
"execution_count": 11,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -309,7 +309,7 @@
" 5, 31, 23, 25, 9, 41, 29, 23, 20, 39, 48, 47, 9, 14, 32])"
]
},
"execution_count": 158,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -332,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": 159,
"execution_count": 12,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -354,7 +354,7 @@
},
{
"cell_type": "code",
"execution_count": 160,
"execution_count": 13,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -379,7 +379,7 @@
"Length: 100, dtype: int64"
]
},
"execution_count": 160,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
@@ -390,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": 161,
"execution_count": 14,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -415,7 +415,7 @@
"Length: 100, dtype: int64"
]
},
"execution_count": 161,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@@ -426,7 +426,7 @@
},
{
"cell_type": "code",
"execution_count": 162,
"execution_count": 15,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -451,7 +451,7 @@
"Length: 100, dtype: int64"
]
},
"execution_count": 162,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
@@ -462,7 +462,7 @@
},
{
"cell_type": "code",
"execution_count": 163,
"execution_count": 16,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -487,7 +487,7 @@
"Length: 100, dtype: float64"
]
},
"execution_count": 163,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
@@ -498,7 +498,7 @@
},
{
"cell_type": "code",
"execution_count": 164,
"execution_count": 17,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -512,7 +512,7 @@
"49"
]
},
"execution_count": 164,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
@@ -523,7 +523,7 @@
},
{
"cell_type": "code",
"execution_count": 165,
"execution_count": 18,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -537,7 +537,7 @@
"1"
]
},
"execution_count": 165,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
@@ -548,7 +548,7 @@
},
{
"cell_type": "code",
"execution_count": 166,
"execution_count": 19,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -562,7 +562,7 @@
"25.5"
]
},
"execution_count": 166,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
@@ -573,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": 167,
"execution_count": 20,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -587,7 +587,7 @@
"25.51"
]
},
"execution_count": 167,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
@@ -598,7 +598,7 @@
},
{
"cell_type": "code",
"execution_count": 168,
"execution_count": 21,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -612,7 +612,7 @@
"14.990566056926294"
]
},
"execution_count": 168,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
@@ -630,7 +630,7 @@
},
{
"cell_type": "code",
"execution_count": 169,
"execution_count": 22,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -649,7 +649,7 @@
"Name: numbers, dtype: bool"
]
},
"execution_count": 169,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@@ -667,7 +667,7 @@
},
{
"cell_type": "code",
"execution_count": 170,
"execution_count": 23,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -686,7 +686,7 @@
"Name: numbers, dtype: int64"
]
},
"execution_count": 170,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
@@ -697,7 +697,7 @@
},
{
"cell_type": "code",
"execution_count": 171,
"execution_count": 24,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -716,7 +716,7 @@
"Name: numbers, dtype: bool"
]
},
"execution_count": 171,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
@@ -728,7 +728,7 @@
},
{
"cell_type": "code",
"execution_count": 172,
"execution_count": 25,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -747,7 +747,7 @@
"Name: numbers, dtype: int64"
]
},
"execution_count": 172,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
@@ -770,7 +770,7 @@
},
{
"cell_type": "code",
"execution_count": 173,
"execution_count": 26,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -784,7 +784,7 @@
},
{
"cell_type": "code",
"execution_count": 174,
"execution_count": 27,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -802,7 +802,7 @@
"Name: fruit, dtype: int64"
]
},
"execution_count": 174,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
@@ -813,7 +813,7 @@
},
{
"cell_type": "code",
"execution_count": 175,
"execution_count": 28,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -831,7 +831,7 @@
"Name: fruit, dtype: int64"
]
},
"execution_count": 175,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
@@ -842,7 +842,7 @@
},
{
"cell_type": "code",
"execution_count": 176,
"execution_count": 29,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -850,6 +850,14 @@
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/0t/s0c95rbs6ds7w_b0d471p0kc0000gn/T/ipykernel_83159/772644344.py:1: FutureWarning: The default value of regex will change from True to False in a future version.\n",
" str_series.str.replace(\"[p]{2}\", \"XX\")\n"
]
},
{
"data": {
"text/plain": [
@@ -860,7 +868,7 @@
"Name: fruit, dtype: object"
]
},
"execution_count": 176,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
@@ -871,7 +879,7 @@
},
{
"cell_type": "code",
"execution_count": 177,
"execution_count": 30,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -880,13 +888,13 @@
},
"outputs": [],
"source": [
"dt_series = pd.Series([20220101, 20220201, 20220301, 20220401], name=\"date\")\n",
"dt_series = pd.Series([20220101, 20220201, 20220301, 20220401], name=\"date\").astype(\"string\")\n",
"dt_series = pd.to_datetime(dt_series, format=\"%Y-%m-%d\")"
]
},
{
"cell_type": "code",
"execution_count": 178,
"execution_count": 31,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -900,7 +908,7 @@
"dtype('<M8[ns]')"
]
},
"execution_count": 178,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
@@ -911,7 +919,7 @@
},
{
"cell_type": "code",
"execution_count": 179,
"execution_count": 32,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -922,14 +930,14 @@
{
"data": {
"text/plain": [
"0 1970-01-01 00:00:00.020220101\n",
"1 1970-01-01 00:00:00.020220201\n",
"2 1970-01-01 00:00:00.020220301\n",
"3 1970-01-01 00:00:00.020220401\n",
"0 2022-01-01\n",
"1 2022-02-01\n",
"2 2022-03-01\n",
"3 2022-04-01\n",
"Name: date, dtype: datetime64[ns]"
]
},
"execution_count": 179,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
@@ -940,7 +948,7 @@
},
{
"cell_type": "code",
"execution_count": 180,
"execution_count": 33,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -952,13 +960,13 @@
"data": {
"text/plain": [
"0 1\n",
"1 1\n",
"2 1\n",
"3 1\n",
"1 2\n",
"2 3\n",
"3 4\n",
"Name: date, dtype: int64"
]
},
"execution_count": 180,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
@@ -969,7 +977,7 @@
},
{
"cell_type": "code",
"execution_count": 181,
"execution_count": 34,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -980,14 +988,14 @@
{
"data": {
"text/plain": [
"0 1\n",
"1 1\n",
"2 1\n",
"3 1\n",
"0 1\n",
"1 32\n",
"2 60\n",
"3 91\n",
"Name: date, dtype: int64"
]
},
"execution_count": 181,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
@@ -998,7 +1006,7 @@
},
{
"cell_type": "code",
"execution_count": 182,
"execution_count": 35,
"metadata": {
"collapsed": false,
"pycharm": {
@@ -1009,14 +1017,14 @@
{
"data": {
"text/plain": [
"0 3\n",
"1 3\n",
"2 3\n",
"3 3\n",
"0 5\n",
"1 1\n",
"2 1\n",
"3 4\n",
"Name: date, dtype: int64"
]
},
"execution_count": 182,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
@@ -1028,21 +1036,26 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.10.4 ('sspai-100-hours-series-python')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"pygments_lexer": "ipython3",
"version": "3.10.4"
},
"vscode": {
"interpreter": {
"hash": "7a101baf08afe636412f97dd4a9fc2e65b6f84f0ec50413bf3e19b04a26b8ba6"
}
}
},
"nbformat": 4,