在models.py中,我创建了以下模型:
from django.db import models
from Data.DataFrame import df #df is the DataFrame
# Create your models here.
class Custumer(models.Model):
ip = models.CharField(max_length=100)
products = df
在python shell中,我完成了以下操作:
In [1]: from app.models import Custumer as C
In [2]: new = C.objects.create(ip='1')
In [3]: new.products
Out[3]:
B000JMLBHU B002AJ7X2C B002D48NBO B0031Y9CPG B0032YXH2E B00359FHZ6 ... B00LDD8NDO B00LF56Y3Q B00LKQNFVE B00LKS5WUY B00LLWDUDK B00LMTLV24
0 0 0 0 0 0 0 ... 0 0 0 0 0 0
[1 rows x 1000 columns]
In [4]: new.products['B000JMLBHU'] =1
In [5]: new.products
Out[5]:
B000JMLBHU B002AJ7X2C B002D48NBO B0031Y9CPG B0032YXH2E B00359FHZ6 ... B00LDD8NDO B00LF56Y3Q B00LKQNFVE B00LKS5WUY B00LLWDUDK B00LMTLV24
0 1 0 0 0 0 0 ... 0 0 0 0 0 0
[1 rows x 1000 columns]
In [6]: new.save()
但是,当我在shell中退出()并再次打开它时,我在第一列中编写的1就消失了。如何修改保存在模型中的数据帧
问题是您没有使用某个列来存储数据,并使其持久化
但是,您可以自己define a field [Django-doc],这是^{} [Django-doc]的修改版本。因此,我们需要实现某种机制,在二进制表示和数据格式之间自动换行
例如,我们可以使用^{} 来序列化和反序列化数据帧。您可以通过以下方式安装
feather-format
:然后我们可以定义我们自己的
DataframeField
:现在,我们可以在模型中使用此字段,通过序列化使数据帧保持不变:
相关问题 更多 >
编程相关推荐