上午。最近我一直在试图实施大熊猫创建机器学习的大型数据表(我试图尽量摆脱numpy,尽我所能)。在熊猫中切片数据框和比较元素
但是 - 我遇到了一些问题 - 即切片熊猫日期帧。
也就是说,我倒是想回到我指定的行数和参考,并特别元素与其他比较数组,这里有一些我实现的代码量小,有的轮廓
import pandas as pd
import csv
import math
import random as nd
import numpy
#create the pandas dataframe from my csv. The Csv is entirely numerical data
#with exception of the first row vector which has column labels
df=pd.read_csv(r"C:\Users\Python\Downloads\Data for Brent - Secondattampatatdfrandomsample.csv")
#I use panda functionality to return a random sample of the data (a subset
#of the array)
df_sample=pd.DataFrame.sample(df,10)
这是在这个指出我想将每个行向量中的第一个元素与原始数据进行比较。具体来说,任何行中的第一个元素都包含一个id号。 如果原始数据帧和采样帧匹配起来的元素,如计算相关联的列元素的3和6个月的平均匹配的ID号码
我想放弃我舒适移动到numpy
和远从pandas
- 但是有培训模式方法,我听到一吨的好东西在pandas
(我的训练是事物的数学方面,而较少的程序开发)。感谢您的输入!
编辑:这里是在数据帧的前11个向量(ID,年,月,X,Y,Z) ID年月XYZ 0 2 2016 2 1130 343.627538 163660.060200 1 2 2016样本输入4 859 913.314513 360633.159400 2 2 2016 5 931 858.548056 93608.190030 3 2 2016 6 489 548.314860 39925.669950 4 2 2016 7 537 684.441725 80270.240060 5 2 2016 8 618 673.887072 124041.560000 6 2 2016 9 1030 644.749493 88975.429980 7 2 2016 10 1001 543.312870 54874.599830 8 2 2016 11 1194 689.053707 79930.230000 9 2 2016 12 673 4 83.644736 27567.749940 10 2 2017 1 912 657.716386 54590.460070 11 2 2017 2 671 682.007537 52514.580380
这里是指定N相同的N元组作为前数据如何样品返回。我用天然熊猫函数来返回的10个向量随机生成的子集出大约9000个条目
2 2016 1 633 877.9282175 75890.97027
5185 2774 2016 4 184 399.418719 9974.375000
9441 4974 2017 2 239 135.520851 0.000000
5134 2745 2017 2 187 217.220657 7711.333333
8561 4063 2017 1 103 505.714286 18880.000000
3328 2033 2016 11 118 452.152542 7622.000000
3503 2157 2016 3 287 446.668831 8092.588235
5228 2791 2016 2 243 400.166008 12655.250000
9380 4708 2017 2 210 402.690583 5282.352941
1631 1178 2016 10 56 563.716667 16911.500000
2700 1766 2016 1 97 486.764151 6449.625000
能否请您提供一些样本数据和期望的输出?目前你的问题对我来说有点困惑。 – miradulo
我会尽可能地说你的问题不仅仅是有点混乱。阅读[HowToAsk](http://stackoverflow.com/help/how-to-ask)和[MinimalCompleteVerifiableExample](http://stackoverflow.com/help/mcve),了解如何拯救自己和他人免于浪费精力。 – piRSquared
如果我的理解正确(谁知道我是否),'df_sample'中的_every_ ID必须在'df'中 – Charlie