8000 Fix errors in Pandas notebook (#194) · DagaEMPA/python-tutorial@1b42590 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b42590

Browse files
authored
Fix errors in Pandas notebook (empa-scientific-it#194)
1 parent 4a478af commit 1b42590

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

library_pandas.ipynb

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@
10031003
"metadata": {},
10041004
"outputs": [],
10051005
"source": [
1006-
"!wc -l data/earthquakes.csv"
1006+
"!wc -l data/01/earthquakes.csv"
10071007
]
10081008
},
10091009
{
@@ -1014,7 +1014,7 @@
10141014
"**Windows users**: if the above doesn't work for you (depends on your setup), then use this instead:\n",
10151015
"\n",
10161016
"```python\n",
1017-
"!find /c /v \"\" data\\earthquakes.csv\n",
1017+
"!find /c /v \"\" data\\01\\earthquakes.csv\n",
10181018
"```\n",
10191019
"\n",
10201020
"\n",
@@ -1030,7 +1030,7 @@
10301030
"metadata": {},
10311031
"outputs": [],
10321032
"source": [
1033-
"!ls -lh data | grep earthquakes.csv"
1033+
"!ls -lh data/01 | grep earthquakes.csv"
10341034
]
10351035
},
10361036
{
@@ -1041,7 +1041,7 @@
10411041
"**Windows users**: if the above doesn't work for you (depends on your setup), then use this instead:\n",
10421042
"\n",
10431043
"```python\n",
1044-
"!dir data | findstr \"earthquakes.csv\"\n",
1044+
"!dir data\\01 | findstr \"earthquakes.csv\"\n",
10451045
"```\n",
10461046
"\n",
10471047
"We can even capture the result of a command and use it in our Python code:"
@@ -1054,7 +1054,7 @@
10541054
"metadata": {},
10551055
"outputs": [],
10561056
"source": [
1057-
"files = !ls -lh data\n",
1057+
"files = !ls -lh data/01\n",
10581058
"[file for file in files if 'earthquake' in file]"
10591059
]
10601060
},
@@ -1066,7 +1066,7 @@
10661066
"**Windows users**: if the above doesn't work for you (depends on your setup), then use this instead:\n",
10671067
"\n",
10681068
"```python\n",
1069-
"files = !dir data\n",
1069+
"files = !dir data\\01\n",
10701070
"[file for file in files if 'earthquake' in file]\n",
10711071
"```"
10721072
]
@@ -1088,7 +1088,7 @@
10881088
"metadata": {},
10891089
"outputs": [],
10901090
"source": [
1091-
"!head -n 2 data/earthquakes.csv"
1091+
"!head -n 2 data/01/earthquakes.csv"
10921092
]
10931093
},
10941094
{
@@ -1100,7 +1100,7 @@
11001100
"\n",
11011101
"```python\n",
11021102
"n = 2\n",
1103-
"with open('data/earthquakes.csv', 'r') as file:\n",
1103+
"with open('data/01/earthquakes.csv', 'r') as file:\n",
11041104
" for _ in range(n):\n",
11051105
" print(file.readline(), end='\\r')\n",
11061106
"```\n",
@@ -1116,7 +1116,7 @@
11161116
"metadata": {},
11171117
"outputs": [],
11181118
"source": [
1119-
"!tail -n 1 data/earthquakes.csv"
1119+
"!tail -n 1 data/01/earthquakes.csv"
11201120
]
11211121
},
11221122
{
@@ -1129,7 +1129,7 @@
11291129
"```python\n",
11301130
"import os\n",
11311131
"\n",
1132-
"with open('data/earthquakes.csv', 'rb') as file:\n",
1132+
"with open('data/01/earthquakes.csv', 'rb') as file:\n",
11331133
" file.seek(0, os.SEEK_END)\n",
11341134
" while file.read(1) != b'\\n':\n",
11351135
" file.seek(-2, os.SEEK_CUR)\n",
@@ -1140,7 +1140,7 @@
11401140
"\n",
11411141
"```python\n",
11421142
"n = 2\n",
1143-
"with open('data/earthquakes.csv', 'r') as file:\n",
1143+
"with open('data/01/earthquakes.csv', 'r') as file:\n",
11441144
" print('\\r'.join(file.readlines()[-n:]))\n",
11451145
"```\n",
11461146
"\n"
@@ -1164,7 +1164,7 @@
11641164
"metadata": {},
11651165
"outputs": [],
11661166
"source": [
1167-
"!awk -F',' '{print NF; exit}' data/earthquakes.csv"
1167+
"!awk -F',' '{print NF; exit}' data/01/earthquakes.csv"
11681168
]
11691169
},
11701170
{
@@ -1175,7 +1175,7 @@
11751175
"**Windows users**: if the above or below don't work for you (depends on your setup), then use this instead:\n",
11761176
"\n",
11771177
"```python\n",
1178-
"with open('data/earthquakes.csv', 'r') as file:\n",
1178+
"with open('data/01/earthquakes.csv', 'r') as file:\n",
11791179
" print(len(file.readline().split(',')))\n",
11801180
"```\n",
11811181
"\n",
@@ -1190,7 +1190,7 @@
11901190
"metadata": {},
11911191
"outputs": [],
11921192
"source": [
1193-
"headers = !head -n 1 data/earthquakes.csv\n",
1193+
"headers = !head -n 1 data/01/earthquakes.csv\n",
11941194
"len(headers[0].split(','))"
11951195
]
11961196
},
@@ -1220,7 +1220,7 @@
12201220
"metadata": {},
12211221
"outputs": [],
12221222
"source": [
1223-
"df = pd.read_csv('data/earthquakes.csv')"
1223+
"df = pd.read_csv('data/01/earthquakes.csv')"
12241224
]
12251225
},
12261226
{
@@ -2155,24 +2155,6 @@
21552155
"pd.concat([tsunami, no_tsunami]).shape"
21562156
]
21572157
},
2158-
{
2159-
"cell_type": "markdown",
2160-
"id": "d38495fa-fe5e-4937-9774-b90c0d26e6d9",
2161-
"metadata": {},
2162-
"source": [
2163-
"Note that the previous result is equivalent to running the `append()` method of the dataframe:"
2164-
]
2165-
},
2166-
{
2167-
"cell_type": "code",
2168-
"execution_count": null,
2169-
"id": "8c6be158-f310-42b7-a05e-cd4b6a6e07b2",
2170-
"metadata": {},
2171-
"outputs": [],
2172-
"source": [
2173-
"tsunami.append(no_tsunami).shape"
2174-
]
2175-
},
21762158
{
21772159
"cell_type": "markdown",
21782160
"id": "ba559768-6848-4eca-9b84-04b8b6e78417",
@@ -2189,7 +2171,7 @@
21892171
"outputs": [],
21902172
"source": [
21912173
"additional_columns = pd.read_csv(\n",
2192-
" 'data/earthquakes.csv', usecols=['tz', 'felt', 'ids']\n",
2174+
" 'data/01/earthquakes.csv', usecols=['tz', 'felt', 'ids']\n",
21932175
")\n",
21942176
"pd.concat([df.head(2), additional_columns.head(2)], axis=1)"
21952177
]
@@ -2210,7 +2192,7 @@
22102192
"outputs": [],
22112193
"source": [
22122194
"additional_columns = pd.read_csv(\n",
2213-
" 'data/earthquakes.csv', usecols=['tz', 'felt', 'ids', 'time'], index_col='time'\n",
2195+
" 'data/01/earthquakes.csv', usecols=['tz', 'felt', 'ids', 'time'], index_col='time'\n",
22142196
")\n",
22152197
"pd.concat([df.head(2), additional_columns.head(2)], axis=1)"
22162198
]
@@ -3618,14 +3600,16 @@
36183600
"metadata": {},
36193601
"outputs": [],
36203602
"source": [
3621-
"extra_data = long_df.append([{\n",
3603+
"extra_data = pd.DataFrame([{\n",
36223604
" 'datatype': 'TAVG', \n",
36233605
" 'date': '2018-10-01', \n",
36243606
" 'temp_C': 10, \n",
36253607
" 'temp_F': 50\n",
36263608
"}]).set_index(['date', 'datatype']).sort_index()\n",
36273609
"\n",
3628-
"extra_data['2018-10-01':'2018-10-02']"
3610+
"extra_data = pd.concat([long_df, extra_data])\n",
3611+
"\n",
3612+
"extra_data.head()"
36293613
]
36303614
},
36313615
{

0 commit comments

Comments
 (0)
0