mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-30 15:31:12 +00:00
added conversion to float
This commit is contained in:
parent
ed0eb89f62
commit
8f0944c7cf
|
@ -1,7 +1,7 @@
|
|||
name,column1,column2,column3
|
||||
abc,1.1,4.2,1.2
|
||||
def,2.1,1.4,5.2
|
||||
ghi,1.5,1.2,2.1
|
||||
jkl,1.8,1.1,4.2
|
||||
ghi,1.5,1.2,-2.1
|
||||
jkl,1.8,-1.1,4.2
|
||||
mno,9.4,6.6,6.2
|
||||
pqr,1.4,8.3,8.4
|
||||
|
|
|
|
@ -1,7 +1,7 @@
|
|||
name,column1,column2,column3
|
||||
abc,1.1^,4.2,1.2^
|
||||
abc,1.1*,4.2,1.2
|
||||
def,2.1,1.4,5.2
|
||||
ghi,1.5,1.2,2.1
|
||||
jkl,1.8,1.1^,4.2
|
||||
mno,9.4*,6.6,6.2
|
||||
pqr,1.4,8.3*,8.4*
|
||||
ghi,1.5,1.2,-2.1*
|
||||
jkl,1.8,-1.1*,4.2
|
||||
mno,9.4,6.6,6.2
|
||||
pqr,1.4,8.3,8.4
|
||||
|
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:13c10e46fea51bcbbf203261897bb4d8ea2087e39925e077d452778f78d62b1e"
|
||||
"signature": "sha256:7ce6d9e0e1dc3da5c31fc5f3a5ab7687870a76cd4adaedd6da95bc6451755b12"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -141,7 +141,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 4
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -167,7 +167,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 5
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -207,13 +207,14 @@
|
|||
" \"\"\" Prints CSV file to standard output.\"\"\"\n",
|
||||
" print(50*'-')\n",
|
||||
" for row in csv_content:\n",
|
||||
" row = [str(e) for e in row]\n",
|
||||
" print('\\t'.join(row))\n",
|
||||
" print(50*'-')"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 6
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -238,15 +239,15 @@
|
|||
"name\tcolumn1\tcolumn2\tcolumn3\n",
|
||||
"abc\t1.1\t4.2\t1.2\n",
|
||||
"def\t2.1\t1.4\t5.2\n",
|
||||
"ghi\t1.5\t1.2\t2.1\n",
|
||||
"jkl\t1.8\t1.1\t4.2\n",
|
||||
"ghi\t1.5\t1.2\t-2.1\n",
|
||||
"jkl\t1.8\t-1.1\t4.2\n",
|
||||
"mno\t9.4\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3\t8.4\n",
|
||||
"--------------------------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 7
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -291,7 +292,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 8
|
||||
"prompt_number": 5
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -310,12 +311,12 @@
|
|||
"text": [
|
||||
"first 3 rows:\n",
|
||||
"['name', 'column1', 'column2', 'column3']\n",
|
||||
"['abc', 1.1, 4.2, 1.2]\n",
|
||||
"['def', 2.1, 1.4, 5.2]\n"
|
||||
"['abc', '1.1', '4.2', '1.2']\n",
|
||||
"['def', '2.1', '1.4', '5.2']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 9
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -374,7 +375,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 10
|
||||
"prompt_number": 7
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -393,6 +394,7 @@
|
|||
"print_csv(csv_cont)\n",
|
||||
"\n",
|
||||
"print('\\n\\nCSV sorted by column \"column3\":')\n",
|
||||
"convert_cells_to_floats(csv_cont)\n",
|
||||
"csv_sorted = sort_by_column(csv_cont, 'column3')\n",
|
||||
"print_csv(csv_sorted)"
|
||||
],
|
||||
|
@ -410,8 +412,8 @@
|
|||
"name\tcolumn1\tcolumn2\tcolumn3\n",
|
||||
"abc\t1.1\t4.2\t1.2\n",
|
||||
"def\t2.1\t1.4\t5.2\n",
|
||||
"ghi\t1.5\t1.2\t2.1\n",
|
||||
"jkl\t1.8\t1.1\t4.2\n",
|
||||
"ghi\t1.5\t1.2\t-2.1\n",
|
||||
"jkl\t1.8\t-1.1\t4.2\n",
|
||||
"mno\t9.4\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3\t8.4\n",
|
||||
"--------------------------------------------------\n",
|
||||
|
@ -420,9 +422,9 @@
|
|||
"CSV sorted by column \"column3\":\n",
|
||||
"--------------------------------------------------\n",
|
||||
"name\tcolumn1\tcolumn2\tcolumn3\n",
|
||||
"ghi\t1.5\t1.2\t-2.1\n",
|
||||
"abc\t1.1\t4.2\t1.2\n",
|
||||
"ghi\t1.5\t1.2\t2.1\n",
|
||||
"jkl\t1.8\t1.1\t4.2\n",
|
||||
"jkl\t1.8\t-1.1\t4.2\n",
|
||||
"def\t2.1\t1.4\t5.2\n",
|
||||
"mno\t9.4\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3\t8.4\n",
|
||||
|
@ -430,7 +432,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 11
|
||||
"prompt_number": 8
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -489,13 +491,13 @@
|
|||
" col_index = sorted_csv[0].index(col)\n",
|
||||
" else:\n",
|
||||
" col_index = col\n",
|
||||
" sorted_csv[1][col_index] += marker\n",
|
||||
" sorted_csv[1][col_index] = str(sorted_csv[1][col_index]) + marker\n",
|
||||
" return None"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 12
|
||||
"prompt_number": 9
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -509,7 +511,7 @@
|
|||
" (modifies input CSV content list).\n",
|
||||
" \n",
|
||||
" \"\"\"\n",
|
||||
" for c in csv_cont[0][1:]:\n",
|
||||
" for c in range(1, len(csv_cont[0])):\n",
|
||||
" mark_minmax(csv_cont, c, mark_max, marker)\n",
|
||||
" marked_csv = sort_by_column(csv_cont, 0, False)\n",
|
||||
" return marked_csv"
|
||||
|
@ -517,21 +519,21 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 13
|
||||
"prompt_number": 10
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"import copy\n",
|
||||
"\n",
|
||||
"csv_cont = csv_to_list('../Data/test.csv')\n",
|
||||
"\n",
|
||||
"csv_marked = copy.deepcopy(csv_cont)\n",
|
||||
"mark_all_col(csv_marked, mark_max=True, marker='*')\n",
|
||||
"mark_all_col(csv_marked, mark_max=False, marker='^')\n",
|
||||
"convert_cells_to_floats(csv_marked)\n",
|
||||
"mark_all_col(csv_marked, mark_max=False, marker='*')\n",
|
||||
"print_csv(csv_marked)\n",
|
||||
"\n",
|
||||
"print('^: min-value\\n*: max-value')"
|
||||
"print('*: min-value')"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -542,19 +544,18 @@
|
|||
"text": [
|
||||
"--------------------------------------------------\n",
|
||||
"name\tcolumn1\tcolumn2\tcolumn3\n",
|
||||
"abc\t1.1^\t4.2\t1.2^\n",
|
||||
"abc\t1.1*\t4.2\t1.2\n",
|
||||
"def\t2.1\t1.4\t5.2\n",
|
||||
"ghi\t1.5\t1.2\t2.1\n",
|
||||
"jkl\t1.8\t1.1^\t4.2\n",
|
||||
"mno\t9.4*\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3*\t8.4*\n",
|
||||
"ghi\t1.5\t1.2\t-2.1*\n",
|
||||
"jkl\t1.8\t-1.1*\t4.2\n",
|
||||
"mno\t9.4\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3\t8.4\n",
|
||||
"--------------------------------------------------\n",
|
||||
"^: min-value\n",
|
||||
"*: max-value\n"
|
||||
"*: min-value\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 14
|
||||
"prompt_number": 12
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -603,7 +604,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 15
|
||||
"prompt_number": 13
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -633,17 +634,17 @@
|
|||
"Written CSV file:\n",
|
||||
"--------------------------------------------------\n",
|
||||
"name\tcolumn1\tcolumn2\tcolumn3\n",
|
||||
"abc\t1.1^\t4.2\t1.2^\n",
|
||||
"abc\t1.1*\t4.2\t1.2\n",
|
||||
"def\t2.1\t1.4\t5.2\n",
|
||||
"ghi\t1.5\t1.2\t2.1\n",
|
||||
"jkl\t1.8\t1.1^\t4.2\n",
|
||||
"mno\t9.4*\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3*\t8.4*\n",
|
||||
"ghi\t1.5\t1.2\t-2.1*\n",
|
||||
"jkl\t1.8\t-1.1*\t4.2\n",
|
||||
"mno\t9.4\t6.6\t6.2\n",
|
||||
"pqr\t1.4\t8.3\t8.4\n",
|
||||
"--------------------------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 16
|
||||
"prompt_number": 14
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
|
Loading…
Reference in New Issue
Block a user