|
93 | 93 | }, |
94 | 94 | { |
95 | 95 | "cell_type": "code", |
96 | | - "execution_count": 3, |
| 96 | + "execution_count": 4, |
97 | 97 | "id": "0dad7357-4e14-4d1e-9856-0f6b487aff7b", |
98 | 98 | "metadata": {}, |
99 | 99 | "outputs": [ |
|
160 | 160 | "3 2020-01-03 x19 28" |
161 | 161 | ] |
162 | 162 | }, |
163 | | - "execution_count": 3, |
| 163 | + "execution_count": 4, |
164 | 164 | "metadata": {}, |
165 | 165 | "output_type": "execute_result" |
166 | 166 | } |
|
182 | 182 | }, |
183 | 183 | { |
184 | 184 | "cell_type": "code", |
185 | | - "execution_count": 4, |
| 185 | + "execution_count": 5, |
186 | 186 | "id": "16cd3840-8bcf-411d-97d4-073bd7451543", |
187 | 187 | "metadata": {}, |
188 | 188 | "outputs": [], |
|
192 | 192 | }, |
193 | 193 | { |
194 | 194 | "cell_type": "code", |
195 | | - "execution_count": 36, |
| 195 | + "execution_count": 6, |
196 | 196 | "id": "4831254b-2b1a-4b52-a105-214005c79048", |
197 | 197 | "metadata": {}, |
198 | 198 | "outputs": [ |
|
212 | 212 | "!cat /tmp/data.csv" |
213 | 213 | ] |
214 | 214 | }, |
| 215 | + { |
| 216 | + "cell_type": "code", |
| 217 | + "execution_count": 7, |
| 218 | + "id": "be179048-6908-470d-aab2-e2b3690aea81", |
| 219 | + "metadata": {}, |
| 220 | + "outputs": [], |
| 221 | + "source": [ |
| 222 | + "#| code-fold: true\n", |
| 223 | + "#| output: false\n", |
| 224 | + "\n", |
| 225 | + "df.to_csv(\"/tmp/data.tsv\", sep=\"\\t\", index=None)" |
| 226 | + ] |
| 227 | + }, |
| 228 | + { |
| 229 | + "cell_type": "markdown", |
| 230 | + "id": "7d498565-0f46-40dc-8ad8-56cfcc9f2db6", |
| 231 | + "metadata": {}, |
| 232 | + "source": [ |
| 233 | + "## TSV\n", |
| 234 | + "Similar to CSV, [Tab Separated Values format](https://en.wikipedia.org/wiki/Tab-separated_values) uses Tabs instead of comma to separate values of each line." |
| 235 | + ] |
| 236 | + }, |
| 237 | + { |
| 238 | + "cell_type": "code", |
| 239 | + "execution_count": 9, |
| 240 | + "id": "b530c8be-648d-46dd-913e-1d0bc0534e38", |
| 241 | + "metadata": {}, |
| 242 | + "outputs": [ |
| 243 | + { |
| 244 | + "name": "stdout", |
| 245 | + "output_type": "stream", |
| 246 | + "text": [ |
| 247 | + "date\tid\tage\n", |
| 248 | + "2020-01-01\tx12\t19\n", |
| 249 | + "2020-01-02\tx11\t23\n", |
| 250 | + "2020-01-02\tx3\t22\n", |
| 251 | + "2020-01-03\tx19\t28\n" |
| 252 | + ] |
| 253 | + } |
| 254 | + ], |
| 255 | + "source": [ |
| 256 | + "!cat /tmp/data.tsv" |
| 257 | + ] |
| 258 | + }, |
| 259 | + { |
| 260 | + "cell_type": "markdown", |
| 261 | + "id": "98550025-bf16-4876-81dd-6acd2f058ec5", |
| 262 | + "metadata": {}, |
| 263 | + "source": [ |
| 264 | + "Luckily `pandas` can handle that too." |
| 265 | + ] |
| 266 | + }, |
| 267 | + { |
| 268 | + "cell_type": "code", |
| 269 | + "execution_count": 11, |
| 270 | + "id": "a118b390-3e9c-4bd5-a925-eb68bd089f2a", |
| 271 | + "metadata": {}, |
| 272 | + "outputs": [ |
| 273 | + { |
| 274 | + "data": { |
| 275 | + "text/html": [ |
| 276 | + "<div>\n", |
| 277 | + "<style scoped>\n", |
| 278 | + " .dataframe tbody tr th:only-of-type {\n", |
| 279 | + " vertical-align: middle;\n", |
| 280 | + " }\n", |
| 281 | + "\n", |
| 282 | + " .dataframe tbody tr th {\n", |
| 283 | + " vertical-align: top;\n", |
| 284 | + " }\n", |
| 285 | + "\n", |
| 286 | + " .dataframe thead th {\n", |
| 287 | + " text-align: right;\n", |
| 288 | + " }\n", |
| 289 | + "</style>\n", |
| 290 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 291 | + " <thead>\n", |
| 292 | + " <tr style=\"text-align: right;\">\n", |
| 293 | + " <th></th>\n", |
| 294 | + " <th>date</th>\n", |
| 295 | + " <th>id</th>\n", |
| 296 | + " <th>age</th>\n", |
| 297 | + " </tr>\n", |
| 298 | + " </thead>\n", |
| 299 | + " <tbody>\n", |
| 300 | + " <tr>\n", |
| 301 | + " <th>0</th>\n", |
| 302 | + " <td>2020-01-01</td>\n", |
| 303 | + " <td>x12</td>\n", |
| 304 | + " <td>19</td>\n", |
| 305 | + " </tr>\n", |
| 306 | + " <tr>\n", |
| 307 | + " <th>1</th>\n", |
| 308 | + " <td>2020-01-02</td>\n", |
| 309 | + " <td>x11</td>\n", |
| 310 | + " <td>23</td>\n", |
| 311 | + " </tr>\n", |
| 312 | + " <tr>\n", |
| 313 | + " <th>2</th>\n", |
| 314 | + " <td>2020-01-02</td>\n", |
| 315 | + " <td>x3</td>\n", |
| 316 | + " <td>22</td>\n", |
| 317 | + " </tr>\n", |
| 318 | + " <tr>\n", |
| 319 | + " <th>3</th>\n", |
| 320 | + " <td>2020-01-03</td>\n", |
| 321 | + " <td>x19</td>\n", |
| 322 | + " <td>28</td>\n", |
| 323 | + " </tr>\n", |
| 324 | + " </tbody>\n", |
| 325 | + "</table>\n", |
| 326 | + "</div>" |
| 327 | + ], |
| 328 | + "text/plain": [ |
| 329 | + " date id age\n", |
| 330 | + "0 2020-01-01 x12 19\n", |
| 331 | + "1 2020-01-02 x11 23\n", |
| 332 | + "2 2020-01-02 x3 22\n", |
| 333 | + "3 2020-01-03 x19 28" |
| 334 | + ] |
| 335 | + }, |
| 336 | + "execution_count": 11, |
| 337 | + "metadata": {}, |
| 338 | + "output_type": "execute_result" |
| 339 | + } |
| 340 | + ], |
| 341 | + "source": [ |
| 342 | + "df = pd.read_csv(\"/tmp/data.tsv\", sep=\"\\t\")\n", |
| 343 | + "df" |
| 344 | + ] |
| 345 | + }, |
215 | 346 | { |
216 | 347 | "cell_type": "markdown", |
217 | 348 | "id": "9ffc3c66-3e20-4d95-93bd-f20312f649a0", |
|
851 | 982 | ] |
852 | 983 | }, |
853 | 984 | { |
854 | | - "cell_type": "code", |
855 | | - "execution_count": null, |
856 | | - "id": "17fd5529-094d-463a-98cf-2ca6e7a47746", |
| 985 | + "cell_type": "markdown", |
| 986 | + "id": "b6c484e3-d432-4c77-8df1-c12ac77b3146", |
857 | 987 | "metadata": {}, |
858 | | - "outputs": [], |
859 | | - "source": [] |
| 988 | + "source": [ |
| 989 | + "## Exercises\n", |
| 990 | + "Download from [this public repo](https://github.com/OpenNeuroDatasets/ds005588) the files \n", |
| 991 | + "`dataset_description.json`, `participants.tsv `.\n", |
| 992 | + "\n", |
| 993 | + "1) Read in the file `dataset_description.json` and print the field `Description`.\n", |
| 994 | + "2) Read in the file `participants.tsv ` and print the mean of all the values of the column `age`." |
| 995 | + ] |
860 | 996 | } |
861 | 997 | ], |
862 | 998 | "metadata": { |
|
875 | 1011 | "name": "python", |
876 | 1012 | "nbconvert_exporter": "python", |
877 | 1013 | "pygments_lexer": "ipython3", |
878 | | - "version": "3.10.13" |
| 1014 | + "version": "3.13.3" |
879 | 1015 | } |
880 | 1016 | }, |
881 | 1017 | "nbformat": 4, |
|
0 commit comments