草庐IT

pyspark-dataframes

全部标签

python - Pandas DataFrame Groupby 两列并获取计数

我有一个以下格式的Pandas数据框:df=pd.DataFrame([[1.1,1.1,1.1,2.6,2.5,3.4,2.6,2.6,3.4,3.4,2.6,1.1,1.1,3.3],list('AAABBBBABCBDDD'),[1.1,1.7,2.5,2.6,3.3,3.8,4.0,4.2,4.3,4.5,4.6,4.7,4.7,4.8],['x/y/z','x/y','x/y/z/n','x/u','x','x/u/v','x/y/z','x','x/u/v/b','-','x/y','x/y/z','x','x/u/v/w'],['1','3','3','2','4','2

python - 如何将 pandas DataFrame 的第一列作为一个系列?

我试过了:x=pandas.DataFrame(...)s=x.take([0],axis=1)而s得到的是DataFrame,而不是Series。 最佳答案 >>>importpandasaspd>>>df=pd.DataFrame({'x':[1,2,3,4],'y':[4,5,6,7]})>>>dfxy014125236347>>>s=df.ix[:,0]>>>type(s)>>>==========================================================================

python - Pandas DataFrame 到字典列表

我有以下数据框:customeritem1item2item31applemilktomato2waterorangepotato3juicemangochipswhichIwanttotranslateittolistofdictionariesperrowrows=[{'customer':1,'item1':'apple','item2':'milk','item3':'tomato'},{'customer':2,'item1':'water','item2':'orange','item3':'potato'},{'customer':3,'item1':'juice','i

python - 将特定的选定列提取到新的 DataFrame 作为副本

我有一个有4列的pandasDataFrame,我想创建一个新的DataFrame只有有三列。这个问题类似于:Extractingspecificcolumnsfromadataframe但对于pandas而不是R。以下代码不起作用,引发错误,当然不是pandasnic的方法。importpandasaspdold=pd.DataFrame({'A':[4,5],'B':[10,20],'C':[100,50],'D':[-30,-50]})new=pd.DataFrame(zip(old.A,old.C,old.D))#raisesTypeError:dataargumentcan'

java - PySpark:java.lang.OutofMemoryError:Java 堆空间

我最近在具有24个CPU和32GBRAM的服务器上使用PySpark和Ipython。它只在一台机器上运行。在我的过程中,我想收集大量数据,如下代码所示:train_dataRDD=(train.map(lambdax:getTagsAndText(x)).filter(lambdax:x[-1]!=[]).flatMap(lambda(x,text,tags):[(tag,(x,text))fortagintags]).groupByKey().mapValues(list))当我这样做时training_data=train_dataRDD.collectAsMap()它给了我ou

python - 如何访问 Pandas DataFrame 中嵌入的 json 对象?

TL;DR如果PandasDataFrame中加载的字段本身包含JSON文档,如何以类似Pandas的方式使用它们?目前,我将Twitter库(twython)中的json/字典结果直接转储到Mongo集合中(此处称为用户)。fromtwythonimportTwythonfrompymongoimportMongoClienttw=Twython(......)#Usingmongoasobjectstorageclient=MongoClient()db=client.twitteruser_coll=db.usersuser_batch=...#collectionofuseri

mongodb - 如何将 mongodb 集合中的数据加载到 pandas 的 DataFrame 中?

我是pandas的新手(嗯,对所有“编程”...),但有人鼓励我尝试一下。我有一个mongodb数据库-“test”-带有一个名为“tweets”的集合。我在ipython中访问数据库:importsysimportpymongofrompymongoimportConnectionconnection=Connection()db=connection.testtweets=db.tweetstweet中文档的文档结构如下:entities':{u'hashtags':[],u'symbols':[],u'urls':[],u'user_mentions':[]},u'favorit

json - 将 Pandas DataFrame 转换为 JSON 格式

我有一个PandasDataFrame,它有两列——一列是文件名,另一列是生成时间:FileHourF11F12F21F31我正在尝试将其转换为具有以下格式的JSON文件:{"File":"F1","Hour":"1"}{"File":"F1","Hour":"2"}{"File":"F2","Hour":"1"}{"File":"F3","Hour":"1"}当我使用命令DataFrame.to_json(orient="records")时,我得到以下格式的记录:[{"File":"F1","Hour":"1"},{"File":"F1","Hour":"2"},{"File":"

python - 将 Json 嵌套到具有特定格式的 pandas DataFrame

我需要在pandasDataFrame中以某种格式格式化Json文件的内容,以便我可以运行pandassql来转换数据并通过评分模型运行它。file=C:\scoring_model\json.js("file"的内容如下){"response":{"version":"1.1","token":"dsfgf","body":{"customer":{"customer_id":"1234567","verified":"true"},"contact":{"email":"mr@abc.com","mobile_number":"0123456789"},"personal":{"g

python - pandas Series 和单列 DataFrame 有什么区别?

为什么pandas会区分Series和单列DataFrame?换句话说:Series类存在的原因是什么?我主要使用带有日期时间索引的时间序列,也许这有助于设置上下文。 最佳答案 引用Pandasdocspandas.DataFrame(data=None,index=None,columns=None,dtype=None,copy=False)Two-dimensionalsize-mutable,potentiallyheterogeneoustabulardatastructurewithlabeledaxes(rowsand