如果 Newdata 是 x 列的列表,如何获取唯一列数——第一个元组的成员数。(Len 不重要。)更改“?”的数量。匹配列并使用下面的语句插入。
csr = con.cursor()
csr.execute('Truncate table test.data')
csr.executemany('INSERT INTO test.data VALUES (?,?,?,?)', Newdata)
con.commit()
Run Code Online (Sandbox Code Playgroud) 在 python 列表中,每个元素有两个项目,第一个是 str,第二个是 float
L= [('A', Decimal('52.00')), ('B', Decimal('87.80')), ('G', Decimal('32.50'))]
Run Code Online (Sandbox Code Playgroud)
for loop
我想在元素中使用两个项目
NewL= []
for row in L:
### do something with str
InSql= "SELECT " % str
f= csr.execute(InSql)
ns = list(f)
###do something with float
InSql= "SELECT " % float
f= csr.execute(InSql)
nf = list(f)
NewL.append(str, float,ns, nf)
Run Code Online (Sandbox Code Playgroud) 如果列表LL:
LL = ['foo', bar', 'noo', 'boo',]
在MySQL表中,使用其他ID在列ID中进行测试.
我可以使用以下内容删除LL中ID为ID的所有行:
csr.execute("""DELETE FROM test.test WHERE ID = "Foo"; """)
csr.execute("""DELETE FROM test.test WHERE ID = "bar"; """)
csr.execute("""DELETE FROM test.test WHERE ID = "noo"; """)
csr.execute("""DELETE FROM test.test WHERE ID = "boo"; """)
Run Code Online (Sandbox Code Playgroud)
我怎么能以编程方式做到这一点?
如何创建"foo"
用于原始数据系列的日期时间索引.(例如,每15秒'foo'和每30秒'foo2'的"as".如果原始系列可以插入"基础"数据帧,我想使用'foo'来重铸数据帧.
如果想要组合结合df"foo"和df"foo2",那么内存命中会是用原始数据系列填充foo索引会更好吗?
编辑:之后import pandas
,datetime.timedelta
停止工作
我#!/usr/bin/python
在第一行有一个python脚本.我可以从CLI运行它python myScp.py.
但作为cron脚本的一部分.python脚本无法运行.测试了cron,运行python脚本并可以写入/tmp/crontest.txt
似乎存在目录问题.我测试了os.getcwd().
它的正确...当cron运行脚本时它会抛出一个错误.从CLI运行:/usr/bin/python myScp.py
抛出相同的错误.
Traceback (most recent call last):
File "/myScp.py", line 31, in <module>
execfile(dn2 + 'anotherScpt.py')
IOError: [Errno 2] No such file or directory: './anotherScpt.py'
Run Code Online (Sandbox Code Playgroud) 大多数 toastr 演示仅限客户端。
如果我得到这个 json 数据的服务器推送
[
{"msg": "Mortgage bill paid", "t": "i"}
{"msg": "Account Balance below $3000", "t": "i"}
{"msg": "Received Car payment request", "t": "w"}
]
Run Code Online (Sandbox Code Playgroud)
我将如何使用 toastr 阅读项目并发布 1 和 2 的“信息”,3 的“警告”,右下角可以。我想在吐司之间延迟 2000 次,这样吐司就不会同时到来。
你能指出我的例子,显示类似的东西。toastr 可以做到这一点。从某种意义上说,定时消息传递。
使用pandas groupby获得最后n个实例的平均值的最佳方法是什么?
例如我有一个这样的数据框:
frame = pd.DataFrame({'Student' : ['Bob', 'Bill', 'Bob', 'Bob', 'Bill', 'Joe', 'Joe', 'Bill', 'Bob', 'Joe'],
'Score' : np.random.random(10)})
Run Code Online (Sandbox Code Playgroud)
我如何获得每个学生的最后 3 个分数的平均值。
我有一些非常大的列表,我正在使用(> 1M行),我试图找到一个快速(最快的?)方式,给定一个浮点数,浮点数与浮点数列表相比,找到它的百分比排名与列表范围相比.这是我的尝试,但它非常慢:
X =[0.595068426145485,
0.613726840488019,
1.1532608695652,
1.92952380952385,
4.44137931034496,
3.46432160804035,
2.20331487122673,
2.54736842105265,
3.57702702702689,
1.93202764976956,
1.34720184204056,
0.824997304105564,
0.765782842381996,
0.615110856990126,
0.622708022872803,
1.03211045820975,
0.997225012974318,
0.496352327702226,
0.67103858866700,
0.452224068868272,
0.441842124852685,
0.447584524952608,
0.4645525042246]
val = 1.5
arr = np.array(X) #X is actually a pandas column, hence the conversion
arr = np.insert(arr,1,val, axis=None) #insert the val into arr, to then be ranked
st = np.sort(arr)
RANK = float([i for i,k in enumerate(st) if k == val][0])+1 #Find position
PCNT_RANK = (1-(1-round(RANK/len(st),6)))*100 #Find percentage of value compared to range …
Run Code Online (Sandbox Code Playgroud) 我有以下两个数据框
Data Set A
ID type msg
1 High Lets do
2 Low whats it
3 Medium thats it
Data Set B
ID Accounttype
2 Facebook
3 Linkedin
Run Code Online (Sandbox Code Playgroud)
我如何在加入熊猫的帮助下获得更新的表,它看起来应该像
Updated DatasetA
ID Account type msg
1 High Lets do
2 Facebook Low whats it
3 Linkedin Medium thats it
Run Code Online (Sandbox Code Playgroud)
我可以轻松地在SQL中使用Update和内部联接来完成它,如何在pandas中执行它,我试图做到这一点,但是大多数操作都是针对append / merge的。任何帮助将不胜感激
我在 Pandas 的数据框中有一列缺失值约为 78%。
剩余的 22% 值按以下比率分配给三个标签 - SC、ST、GEN。
SC - 16% ST - 8% GEN - 76%
我需要用上述三个值替换缺失值,以便所有元素的比例保持与上述相同。只要比率保持如上,分配可以是随机的。
我该如何实现?