我有一个没有加载的iPython笔记本文件,大概是因为文件中有太多的输出(打印了数千行结果,旧计算机).
我可以使用记事本编辑文件而不会出现问题,但是复制然后逐个单元地清理代码非常耗时.
有没有办法以不同方式恢复代码,或者要求iPython笔记本只加载代码而不打开文件时打印所有过去的输出?
我试图让 Selenium 打开 Chrome,就像我自己打开它一样,即我应该像 Facebook 一样登录我的帐户。
我有以下代码:
def startChrome():
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")
driver = webdriver.Chrome(chrome_options=options)
driver.set_page_load_timeout(60)
return driver
driver = startChrome()
url = 'https://www.facebook.com'
driver.get(url)
Run Code Online (Sandbox Code Playgroud)
然而,这让我在没有登录的情况下进入 Facebook。我已经检查过chrome://version并且个人资料 URL 实际上是正确的。我究竟做错了什么?
使用 Python 3,Chrome 版本 63.0.3239.84,MacOS High Sierra
python selenium google-chrome headless-browser google-chrome-headless
是否有一个简单的方法/模块在python中进行分组操作,数据集太大而无法放入内存中?
我通常会使用pandas,但它会因大型数据集而崩溃.
我有以下简单的wordcount Python脚本.
from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("local").setAppName("My App")
sc = SparkContext(conf = conf)
from operator import add
f=sc.textFile("C:/Spark/spark-1.2.0/README.md")
wc=f.flatMap(lambda x: x.split(" ")).map(lambda x: (x,1)).reduceByKey(add)
print wc
wc.saveAsTextFile("wc_out.txt")
Run Code Online (Sandbox Code Playgroud)
我正在使用此命令行启动此脚本:
spark-submit "C:/Users/Alexis/Desktop/SparkTest.py"
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
15/04/20 18:58:01 WARN Utils: Your hostname, AE-LenovoUltra resolves to a loopba
ck address: 127.0.1.2; using 192.168.1.63 instead (on interface net0)
15/04/20 18:58:01 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another
address
15/04/20 18:58:10 WARN NativeCodeLoader: Unable to load native-hadoop …Run Code Online (Sandbox Code Playgroud) 我有两个数据框(logs和failures),我想将其合并,以便添加logs一列,其值是在“故障”中找到的最接近日期的值。
生成logs,failures和所需代码的代码output如下:
import pandas as pd
logs=pd.DataFrame({'date-time':pd.Series(['23/10/2015 10:20:54','22/10/2015 09:51:32','21/10/2015 06:51:32','28/10/2015 16:59:32','25/10/2015 04:41:32','24/10/2015 11:50:11']),'var1':pd.Series([0,1,3,1,2,4])})
logs['date-time']=pd.to_datetime(logs['date-time'])
failures=pd.DataFrame({'date':pd.Series(['23/10/2015 00:00:00','22/10/2015 00:00:00','21/10/2015 00:00:00']),'failure':pd.Series([1,1,1])})
failures['date']=pd.to_datetime(failures['date'])
output=pd.DataFrame({'date-time':pd.Series(['23/10/2015 10:20:54','22/10/2015 09:51:32','21/10/2015 06:51:32','28/10/2015 16:59:32','25/10/2015 04:41:32','24/10/2015 11:50:11']),'var1':pd.Series([0,1,3,1,2,4]),'closest_failure':pd.Series(['23/10/2015 00:00:00','22/10/2015 00:00:00','21/10/2015 00:00:00','23/10/2015 00:00:00','23/10/2015 00:00:00','23/10/2015 00:00:00'])})
output['date-time']=pd.to_datetime(output['date-time'])
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?实际数据集非常大,因此效率也是一个问题。
我正在尝试使用 pip安装此软件包:https : //github.com/gka/pyshppeocode。
我收到错误消息:
Cannot unpack file c:\users\alexis\appdata\local\temp\pip-xljjwr-unpack\pyshpgeocode.git (downloaded from c:\users\alexis\appdata\local\temp\pip-jtyh7r-build, content-type: text/html; charset=utf-8); cannot detect archive format
Cannot determine archive format of c:\users\alexis\appdata\local\temp\pip-jtyh7r-build
Run Code Online (Sandbox Code Playgroud)
这是什么问题,我还能如何安装这个包?
我有一个pandas数据帧,具有以下结构:
DF_Cell, DF_Site
C1,A
C2,A
C3,B
C4,B
C5,B
Run Code Online (Sandbox Code Playgroud)
我有一个很长的循环(1亿次迭代),其中我逐个处理对应于DataFrame中"DF_Cell"列的字符串(第一次循环迭代创建C1,第二次迭代创建C2等等).
我想在数据帧中查找与循环中处理的单元格(DF_Cell)对应的DF_Site.
我能想到的一种方法是将处理过的单元格放在一个单元格的DataFrame中然后对其进行左合并,但这对于这样的大数据来说效率太低了.
有没有更好的办法?
我输入了一些看起来像 DF1 的东西(下面要生成的代码),并希望输出一些看起来像 DF2 的东西。
这个想法是为每一行找到该行中具有最高值的列名,相应的值,以及该行中具有第二大值的列名,以及它的对应值。
有没有简单的方法可以用熊猫做到这一点?
import pandas as pd
DF1 = pd.DataFrame({'User' : pd.Series(["Line1","Line2","Line3", "Line4"], index=['1', '2','3','4']), 'Var1' : pd.Series([9,12,3,21], index=['1', '2','3','4']),'Var2' : pd.Series([8,16,3,2], index=['1', '2','3','4']),'Var3' : pd.Series([7,5,6,9], index=['1', '2','3','4']),'Var4' : pd.Series([10,13,20,20], index=['1', '2','3','4']),'Var5' : pd.Series([8,2,13,1], index=['1', '2','3','4']),'Var6' : pd.Series([4,4,7,11], index=['1', '2','3','4']),'Var7' : pd.Series([15,13,4,7], index=['1', '2','3','4'])})
DF1
DF2 = pd.DataFrame({'User' : pd.Series(["Line1","Line2","Line3", "Line4"], index=['1', '2','3','4']), 'Max1Name' : pd.Series(["Var7","Var2","Var4","Var1"], index=['1', '2','3','4']),'Max1Value' : pd.Series([15,16,20,21], index=['1', '2','3','4']),'Max2Name' : pd.Series(["Var4","Var4","Var5","Var4"], index=['1', '2','3','4']),'Max2Value' : pd.Series([10,13,13,20], index=['1', '2','3','4'])})
DF2
Run Code Online (Sandbox Code Playgroud) 还有其他类似的问题,但不同之处在于我的数据框架已经有很多列,其中只有一列需要拆分.
我有一个大型数据帧(数百列,数百万行).当在字符串中找到字符("|")时,我想拆分其中一列.
所有值只有一个"|".
对于固定长度,我会这样做:df ['StateInitial'] = df ['state'].str [:2]
我希望我可以用string.index("|")替换2,但是如何调用字符串呢?
我在 jupyter 笔记本上使用 seaborn,并且想要一个滑块来更新图表。我的代码如下:
from ipywidgets import interact, interactive, fixed, interact_manual
import numpy as np
import seaborn as sns
from IPython.display import clear_output
def f(var):
print(var)
clear_output(wait=True)
sns.distplot(list(np.random.normal(1,var,1000)))
interact(f, var=10);
Run Code Online (Sandbox Code Playgroud)
问题:每次移动滑块时,图表都会重复。我该如何更新图表?