回答編集履歴
1
コメントで返信したコードの追記
test
CHANGED
@@ -75,3 +75,43 @@
|
|
75
75
|
main()
|
76
76
|
|
77
77
|
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
以下追記
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
コメント欄ではコードを埋め込めなかったので同じコードを貼っておきます
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
``` python3
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
from math import nan
|
94
|
+
|
95
|
+
import pandas as pd
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def main():
|
100
|
+
|
101
|
+
df = pd.DataFrame(["40代男性", "20代女性", nan, "男性"], columns=["user"])
|
102
|
+
|
103
|
+
df['gender']=df['user'].apply(lambda x: "不明" if not type(x) is str else ("女性" if "女性" in x else ("不明")))
|
104
|
+
|
105
|
+
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 "不明")))))))))))
|
106
|
+
|
107
|
+
print(df)
|
108
|
+
|
109
|
+
return
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
if __name__ == '__main__':
|
114
|
+
|
115
|
+
main()
|
116
|
+
|
117
|
+
```
|