回答編集履歴
1
コメントで返信したコードの追記
answer
CHANGED
@@ -36,4 +36,24 @@
|
|
36
36
|
|
37
37
|
if __name__ == '__main__':
|
38
38
|
main()
|
39
|
+
```
|
40
|
+
|
41
|
+
以下追記
|
42
|
+
|
43
|
+
コメント欄ではコードを埋め込めなかったので同じコードを貼っておきます
|
44
|
+
|
45
|
+
``` python3
|
46
|
+
|
47
|
+
from math import nan
|
48
|
+
import pandas as pd
|
49
|
+
|
50
|
+
def main():
|
51
|
+
df = pd.DataFrame(["40代男性", "20代女性", nan, "男性"], columns=["user"])
|
52
|
+
df['gender']=df['user'].apply(lambda x: "不明" if not type(x) is str else ("女性" if "女性" in x else ("不明")))
|
53
|
+
df['agerange']=df['user'].apply(lambda x: "不明" if not type(x) is str else ("10代" if "10代" in x else ("20代" if "20代" in x else ("30代" if "30代" in x else ("40代" if "40代" in x else ("50代" if "50代" in x else ("60代" if "60代" in x else ("70代" if "70代" in x else( "80代" if "80代" in x else ("90代" if "90代" in x else ("100代" if "100代" in x else "不明")))))))))))
|
54
|
+
print(df)
|
55
|
+
return
|
56
|
+
|
57
|
+
if __name__ == '__main__':
|
58
|
+
main()
|
39
59
|
```
|