--It is difficult to categorize this article ――I don't know what the problem is in the first place, so I can't decide the title or category first.
I could have imagined it because it was pasted in the image, is it jupyter as expected?
docker-compose.yml
version: '3'
services:
jupyter:
image: jupyter/scipy-notebook
ports:
- 10000:8888
volumes:
- $PWD:/home/jovyan/work
command: start.sh jupyter lab --NotebookApp.token=''
$ docker-compose up
Go to http: // localhost: 10000 / and look at the console.
I'd be happy if someone had the code when trying it, but I didn't have it so I hit it by hand
Source 1
data = {'name': ['Ryo', 'Kaori', 'Hideyuki', 'Hayato', 'Miki', 'Saeko'],
'gender': ['M', 'F', 'M', 'M', 'F', 'F'],
'height': [186, 168, 175, 210, 160, 163],
'weight': [72, 47, 62, 90, None, numpy.NaN],
'age': [30, 20, None, numpy.NaN, 23, 25],
'size': ['L', 'M', 'L', 'XL', None, 'S']
}
error
NameError: name 'numpy' is not defined
After modification 1
import numpy
data = {'name': ['Ryo', 'Kaori', 'Hideyuki', 'Hayato', 'Miki', 'Saeko'],
'gender': ['M', 'F', 'M', 'M', 'F', 'F'],
'height': [186, 168, 175, 210, 160, 163],
'weight': [72, 47, 62, 90, None, numpy.NaN],
'age': [30, 20, None, numpy.NaN, 23, 25],
'size': ['L', 'M', 'L', 'XL', None, 'S']
}
Source 2
size2int = {'S': 1, 'M': 2, 'L': 3, 'XL': 4}
df['size'] = df['size'].map(size2int)
df
error
NameError: name 'df' is not defined
Well, that's right
After modification 2
import pandas as pd
df = pd.DataFrame(data)
#size2int means size to int
size2int = {'S': 1, 'M': 2, 'L': 3, 'XL': 4}
df['size'] = df['size'].map(size2int)
df
It's done. Why doesn't it work? Insufficient esper power.
The expectation is that I overwrote the size
column once with size2int missing. After that, it is only NaN.
sample
size2int = {'S': 1, 'M': 2, 'L': 3, 'XL': 4}
Like
Then, let's try data → df again. Is something.
Really?
Fail once
import pandas as pd
df = pd.DataFrame(data)
size2int = {}
df['size'] = df['size'].map(size2int)
df
No matter how many times I do it
size2int = {'S': 1, 'M': 2, 'L': 3, 'XL': 4}
df['size'] = df['size'].map(size2int)
df
Can be reproduced for the time being
――Mostly you stumble where it doesn't really matter ――It is surprisingly important to create an environment where you can try it from the beginning ――Docker is convenient when you want to create an environment quickly. Because it is a code, you can pass it
Recommended Posts