K
K
Kate Golovacheva2021-01-22 13:18:49
Django
Kate Golovacheva, 2021-01-22 13:18:49

How to get a link in the form of text from a line entered by the user and insert it into pd.read_csv('Here is a type of link')?

I understand that I'm just a programmer larva, so don't judge me for my possible stupidity. The question is how to get a link in the form of text from a line entered by the user and insert it into pd.read_csv('Here is a type of link').
My code in forms.py
from .models import Anser
from django.forms import ModelForm, TextInput, Textarea

class AnserForm(ModelForm):
class Meta:
model = Anser
fields = ['url_csv']
widgets = {
'title':TextInput(attrs ={
'class':'form-control',
'placeholder':'File link'
})
}
My code in views.py:
from django.shortcuts import render
from .models import Anser
from .forms import AnserForm
import pandas as pd
import sklearn as tree
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV

def index(request):
result = Anser.objects.all()
error = ''
if request.method == 'POST':
form = AnserForm(request.POST)
if form.is_valid():
form.save( )
else:
error = 'Form not found'
form = AnserForm()

titanic_data=pd.read_csv(AnserForm())
X=titanic_data.drop(['Yfactor'],axis=1)
y=titanic_data.Yfactor
clf=tree.DecisionTreeClassifier(criterion='entropy',max_depth= 4)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.33, random_state = 42)
clf_rf = RandomForestClassifier()
parametrs={'n_estimators':[18,20,30],'max_depth': [2 ,5,7,10]} grid_search_cv_clf = GridSearchCV
(clf_rf, parametrs, cv=5)
grid_search_cv_clf.fit(X_train, y_train )list(X_train),
'feature_importances':feature_importances})
search = feature_importances_df.sort_values('feature_importances',ascending=False)
data = {
'search': search,
'error': error
}
return render(request, 'main/index.html', data )
def about(request):
return render(request, 'main/about.html')
def contact(request):
return render(request, 'main/contact.html')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prizrak256, 2021-01-22
@Prizrak256

If I understand the question correctly, then something like this:

# Получаем ссылку пользователя в любую переменную, допустим link
pd.read_csv(f'{link}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question