嗨,我有一个清单,
my_list=["one two","three four"]
Run Code Online (Sandbox Code Playgroud)
我想要的输出是,
output_list=['one', 'two', 'three', 'four']
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码,
my_list=" ".join(my_list)
output_list=my_list.split()
output_list,
['one', 'two', 'three', 'four']
Run Code Online (Sandbox Code Playgroud)
它工作正常,我得到我的输出,我希望,解决方案比这更短的解决方案可以实现相同,在此先感谢!
I have a df,
Name Count
Ram 1
ram 2
raM 1
Arjun 3
arjun 4
Run Code Online (Sandbox Code Playgroud)
My desired output df,
Name Count
Ram 4
Arjun 7
Run Code Online (Sandbox Code Playgroud)
I tried groupby but I cannot achieve the desired output, please help
我有两个数据框,
df1=pd.DataFrame({"Req":["Req 1","Req 2","Req 3"],"Count":[1,2,1]})
Req Count
0 Req 1 1
1 Req 2 2
2 Req 3 1
Run Code Online (Sandbox Code Playgroud)
df2=pd.DataFrame({"Req":["Req 1","Req 2"],"Count":[0,1]})
Req Count
0 Req 1 0
1 Req 2 1
Run Code Online (Sandbox Code Playgroud)
我正在尝试根据“Req”列合并这些 df
我想要的输出是,
Req total from_1 from_2
Req 1 1 1 0
Req 2 3 2 1
Req 3 1 1 0
Run Code Online (Sandbox Code Playgroud)
我试过了,pd.merge(df1, df2, on = "Req", )但没有给出我想要的输出,请帮忙,提前致谢!
嗨,我正在尝试在 Flask 方法中传递一个 URL,
My url: https://example.org/de?=fg&hi=jk
Run Code Online (Sandbox Code Playgroud)
我尝试了以下步骤:
@app.route('/flip/<path:url>')
def flip(url):
return "retrievved url:"+str(url)
calling the url : localhost:8200//flip/https://example.org/de?=fg&hi=jk
returns : `https://example.org/de`
and another method,
@app.route('/flip')
def flip(url):
url=request.args.get('url')
return "retrievved url:"+str(url)
calling the url: localhost:8200//flip?url=https://example.org/de?=fg&hi=jk
returns : 'https://example.org/de?=fg'
Run Code Online (Sandbox Code Playgroud)
我的预期输出应该返回我们传递的整个 url https://example.org/de?=fg&hi=jk
请帮忙,提前致谢
我有两个数据帧,
df1
Name | std
kumar | 8
Ravi | 10
Sri | 2
Ram | 4
df2,
Name | std
Sri | 2
Ram | 4
Run Code Online (Sandbox Code Playgroud)
我想从df1中减去df2行,我试过了,
df1.subtract(df2,fill_value=None)
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误,
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud)
我想要的输出,
df3
Name | std
kumar | 8
Ravi | 10
Run Code Online (Sandbox Code Playgroud) 我有一个具有以下结构的数据框,
| Date | Item | Location | Event |
|------------|-------:|----------|---------|
| 01-06-2019 | Item_1 | Loc_1 | Event_1 |
| 01-06-2019 | Item_1 | Loc_1 | Event_1 |
| 02-06-2019 | Item_1 | Loc_1 | Event_1 |
| 02-06-2019 | Item_1 | Loc_1 | Event_2 |
| 02-06-2019 | Item_1 | Loc_2 | Event_2 |
| 02-06-2019 | Item_2 | Loc_1 | Event_3 |
| 03-06-2019 | Item_2 | Loc_1 | Event_3 |
| 03-06-2019 | Item_2 | Loc_1 …Run Code Online (Sandbox Code Playgroud) 我刚开始学习机器学习,在练习其中一项任务时,我遇到了价值错误,但我遵循了与讲师相同的步骤。
我收到值错误,请帮忙。
天涯
Country Name
0 AUS Sri
1 USA Vignesh
2 IND Pechi
3 USA Raj
Run Code Online (Sandbox Code Playgroud)
首先我执行了标签编码,
X=dff.values
label_encoder=LabelEncoder()
X[:,0]=label_encoder.fit_transform(X[:,0])
out:
X
array([[0, 'Sri'],
[2, 'Vignesh'],
[1, 'Pechi'],
[2, 'Raj']], dtype=object)
Run Code Online (Sandbox Code Playgroud)
然后对同一个 X 进行一次热编码
onehotencoder=OneHotEncoder( categorical_features=[0])
X=onehotencoder.fit_transform(X).toarray()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError Traceback (most recent call last)
<ipython-input-472-be8c3472db63> in <module>()
----> 1 X=onehotencoder.fit_transform(X).toarray()
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in fit_transform(self, X, y)
1900 """
1901 return _transform_selected(X, self._fit_transform,
-> 1902 self.categorical_features, copy=True)
1903
1904 def _transform(self, X):
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in _transform_selected(X, transform, selected, copy)
1695 X : …Run Code Online (Sandbox Code Playgroud) python preprocessor scikit-learn sklearn-pandas one-hot-encoding
我有这样的清单,
my_list = ["one two","three two"]
Run Code Online (Sandbox Code Playgroud)
我想把它转换成,
out_list=["one","two","three","two"]
Run Code Online (Sandbox Code Playgroud)
我正在做的输出,
out_list=[item.split() for item in my_list]
out_list=sum(out_list,[])
Run Code Online (Sandbox Code Playgroud)
我正在寻找最简单的方法在一行中做同样的事情,但我希望有一个简单的方法在python中做到这一点,提前谢谢!
python ×8
pandas ×4
dataframe ×3
list ×2
flask ×1
listview ×1
preprocessor ×1
python-3.x ×1
regex ×1
request ×1
scikit-learn ×1
web-services ×1