2017-03-20 41 views
1

我使用django-rest-framework來製作我的數據api。我正在製作一個應用程序,該程序會考慮用戶數據並使用Pandas從該數據中刪除異常值。我能夠使用django模板在前端展示我的數據,但不知何故,我無法使用django-rest-framework製作包含統計數據的API。有人可以解釋它,請幫我糾正我的錯誤,並提供必要的代碼Django Rest Api與熊貓

這裏是我的代碼

class Data(models.Model): 
    Name = models.CharField(max_length=30,null=True,blank=True) 
    Age = models.IntegerField(null=True,blank=True) 
    Weight = models.FloatField(null=True,blank=True) 
    Height = models.FloatField(null=True,blank=True) 
    Sugar = models.FloatField(null=True,blank=True) 
    def __unicode__(self): 
     return self.Name 

我的序列化器類

class DataSerializer(serializers.ModelSerializer): 
    class Meta: 
     model = Data 
     fields = '__all__' 

我views.py

def my_view(request): 
    con = sqlite3.connect("db.sqlite3") 
    df = pd.read_sql_query("SELECT * from visualapp_health", con) 
    a = df.fillna(0) 
    a['x-Mean'] = abs(a['Age'] - a['Age'].mean()) 
    a['1.96*std'] = 1.96*a['Age'].std() 
    a['Outlier'] = abs(a['Age'] - a['Age'].mean()) > 1.96*a['Age'].std() 
    con.close() 
    return render(request, 'visual.html', {'visual': a}) 

我能夠在使用Django模板時獲取所有數據,但不知何故,我無法瞭解如何使用django-rest-framework製作所有數據的API。

using django templates

Using api all data is not visible

回答

1

我終於得到了它,我用Django的大熊貓庫和它的工作,也沒有需要連接到數據庫只是轉換你的Django的queryset到大熊貓數據幀。