python - 如何使用 pandas/python 将变量值放在列表的另一个列表中
问题描述
我有两个变量:
date = 2018-10-25
因为所有日期都被存储
df =[['Euro', 0.8762059999999999], ['British Pound', 0.7755920000000001], ['Indian Rupee', 73.246211], ['Australian Dollar', 1.4093959999999999], ['Canadian Dollar', 1.308288], ['Singapore Dollar', 1.379124], ['Swiss Franc', 0.999036], ['Malaysian Ringgit', 4.1631849999999995], ['Japanese Yen', 112.293159], ['Chinese Yuan Renminbi', 6.944638]]
就像那个列表一样。
我想要输出:[['Euro',2018-10-25, 0.8762059999999999],['British Pound', 2018-10-25, 0.7755920000000001],['Indian Rupee',2018-10-25, 73.246211],....]
就像使用 pandas/python 的 for 循环列表的所有元素一样。
并希望将其存储在 Mysql 数据库中 那么,它的查询是怎么来的呢?
所以请帮助指导我该怎么做。我试过这个但不工作:
total = []
for i in df:
total = [df[0][0], date, df[0][1]]
解决方案
超级简单:
date = "2018-10-25"
df =[['Euro', 0.8762059999999999], ['British Pound', 0.7755920000000001], ['Indian Rupee', 73.246211], ['Australian Dollar', 1.4093959999999999], ['Canadian Dollar', 1.308288], ['Singapore Dollar', 1.379124], ['Swiss Franc', 0.999036], ['Malaysian Ringgit', 4.1631849999999995], ['Japanese Yen', 112.293159], ['Chinese Yuan Renminbi', 6.944638]]
// Loop through df, i being the position, and append the date to the end of each
// of those arrays under df, because df is a multi dimensional array.
for i in df:
i.insert(1,date)
print(df)
推荐阅读
- python - 是否有更简洁的方法来处理 for 循环中的(连续)独占 if 语句?
- arrays - 汇编语言中String和Array的区别
- javascript - 如何将反应状态中的值作为变量包含在 API 调用中的查询参数中
- xml - Jupyter Notebook + Pyspark - 加载 spark-xml 包时遇到问题
- python - 如何使用“objects.create”将数据添加到 Django 的 mysql 表中
- php - 如何使 /login 路由仅适用于 Symfony4 中的匿名用户?
- python-3.x - 关于合并文件和字符串序列或循环
- dart - 将今天的日期与 SqfLite 数据库中存储的日期进行比较
- python - 在 Windows 10 上通过 Python 2.7 Ubuntu 播放声音
- c# - 您可以使用 Visual Studio 2017 调试在 Google Android Emulator 中运行的 Android 应用吗?