【问题标题】:Is there a way to find patterns in a column in a Pandas DataFrame有没有办法在 Pandas DataFrame 的列中查找模式
【发布时间】:2020-03-06 12:39:19
【问题描述】:

我有来自较大的datasetPandas DataFramemissing dataframesweb_id 列包含 larger dataframe 中缺少的 ids

我正在尝试以较大的dataset 中缺少的方式找到一种模式。

例如,以下代码可在您的本地计算机上重现。以下是我目前的数据集示例:

pd.DataFrame({
"web_id": [43291, 43300, 43313, 43316, 43335, 43345, 43346, 43353, 43361, 43373, 43383, 43387, 43416],
"date": "12/17/2019"
})

我相信缺失中存在某种模式。如何找到web_id 的序列以进一步了解较大的dataset 中的数据是如何丢失的?

在此先感谢

【问题讨论】:

  • “我相信缺失中存在某种模式。” 是什么让你这么认为?这不是关于特定编程问题的问题,充其量只是某种谜题。
  • 我投票决定将此问题作为离题结束,因为它与特定的编程问题无关。

标签: python pandas dataframe mathematical-optimization missing-data


【解决方案1】:
x = pd.DataFrame({ "web_id": [43291, 43300, 43313, 43316, 43335,
43345, 43346, 43353, 43361, 43373, 43383, 43387, 43416], })

ls = [] 
for i in x.values:  
   for j in i:        
       ls.append(j)

for i in range(len(ls)-1):    
    print(ls[i+1] - ls[i])

这将打印出列中每个值之间的差异。我没有注意到任何数学序列,至少使用这种差分方法。

输出:9, 13, 3、 19, 10, 1、 7、 8、 12, 10, 4、 29

其实你可以到这里https://oeis.org/去验证之前有没有找到这个序列。似乎并非如此。祝你好运!

【讨论】:

  • 这不起作用。你能检查你的第三行代码吗?存在缩进错误
  • 超级!丹克很好的参考
  • 缩进修复:)
  • 当我用我的数据集尝试它时。我收到错误:TypeError: 'numpy.int64' object is not iterable
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2020-11-14
  • 2019-11-13
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
相关资源
最近更新 更多