python - 熊猫不导入 excel 更改
问题描述
我正在一个 python/django 项目中工作,我从 Excel 文件中导入一些数据。
我需要导入的简化视图是:
网址.py
re_path(r'^product_push/', sick_data_views.Products_List_upload, name='product-push')
视图.py
def ID_push():
Products.objects.all().delete()
df = product.importDataFrameProducts()
print(df)
data = Products(
ID = str(df['ID'].tolist()).replace("'",'\"'),
)
data.save()
def Products_List_upload(request):
ID_push()
return HttpResponse(status=204)
模型.py
class Products(models.Model):
ID = models.CharField(max_length=1000000)
列表.py
class product:
def __init__(self, excel_path = os.path.dirname(os.path.realpath(__file__))+"\\A_Products.xlsx"):
self.__df = self.importDataFrameExamplesList(excel_path)
def importDataFrameExamplesList(self, excel_path):
# Load json
df = pd.read_excel(excel_path, keep_default_dates=False)
return df
def importDataFrameProducts(self):
return self.__df
当我运行服务器时,导入过程运行并且我得到正确的输出:视图调用 lists.py 并更新值。比方说:
ID
1
2
3
但是,如果我将 Excel 文件更改为其他值,例如:
ID
4
2
3
如果我运行 localhost:8000/product_push,则导入返回 Excel 文件的旧值 (1,2,3)。我不需要自动更新,但是当我运行推送 url 时,我应该能够获取更新后的值。熊猫是否在缓存中存储了一些变量?因为我只有重新运行服务器后才能解决这个问题。提前致谢。
解决方案
推荐阅读
- html - 如何使用 golang 下载包含所有文件和子目录的 HTTP 目录,因为它们出现在在线文件/文件夹列表中?
- java - “camel-activemq”与“activemq-camel”之间的区别
- python-3.x - IndexError: index 1 is out of bounds for axis 0 with size 1 //Python (jupyter notebook)
- java - Java 程序结构
- python - 如何为我的代码的每一行添加一个新数字到我的列表中?
- web-component - 点亮模板中的 vaadin-item @click 事件
- perl - Strawberry Perl 模块安装问题
- javascript - TypeError:无法读取 null 的属性(读取“addEventListener”)
- java - JNI 原生类方法获取错误的参数值
- python-3.x - 在大型嵌套字典中查找特定键