小编Chr*_*ris的帖子

将 X 和 Y 数组转换为频率网格

我想将两个数组(x 和 y)转换为频率nxn矩阵(n = 5),指示每个单元格包含的点数。它包括将两个变量重新采样为五个间隔,并计算每个单元格的现有点数。

我曾尝试使用 pandas pivot_table但不知道引用每个轴坐标的方式。X 和 Y 数组是两个因变量,包含 0 到 100 之间的值。

我真的很感激有人的帮助。非常感谢您提前。

这是代码的示例:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Arrays example. They are always float type and ranging 0-100. (n_size array = 15)
x = 100 * np.random.random(15)
y = 100 * np.random.random(15)

# Df created for trying to pivot and counting values per cell
df = pd.DataFrame({'X':x,'Y':y})

# Plot the example …
Run Code Online (Sandbox Code Playgroud)

python numpy pivot-table matrix pandas

19
推荐指数
2
解决办法
461
查看次数

计划从 Google BigQuery 导出到 Google Cloud Storage

我是 Google Cloud 的新手,想了解有关如何安排查询并将其导出到 Google Cloud Storage 的最佳用例。我看过有关如何手动导出数据的文档,但找不到任何有关以自动方式执行此操作的具体内容。有没有最好的方法来解决这个问题?

谢谢

scheduled-tasks google-cloud-storage google-bigquery

6
推荐指数
2
解决办法
3883
查看次数

获取分区镶木地板数据框的最新模式

我们开始使用 spark 和 parquet 文件在 hadoop 集群中收集数据……但是我们很难保证 parquet 模式在未来不会改变。我们试图找到阅读镶木地板的最佳方式,即使架构发生变化......

我们要实现的规则是最新的镶木地板文件将作为我们的参考...

我们进行了不同的测试,包括:

spark.read.parquet("test").filter("year=2017 and month=10 and day>=15")
spark.read.parquet("test/year=2017/month=10/day=17", "test/year=2017/month=10/day=16", "test/year=2017/month=10/day=15")
// tested with different order
spark.read.parquet("test/year=2017/month=10/day={15,16,17}")
Run Code Online (Sandbox Code Playgroud)

等等...

并且 read 方法保留的模式始终是最旧的模式(即 10 月 15 日的模式)。

有人知道如何获得最新的模式(即 10 月 17 日的模式)吗?

当然spark.read.option("mergeSchema", "true")不起作用,因为如果我们在最新的镶木地板中放下一列,它不会删除一列。我们在这里进行了超过 3 天的测试......但它可能会在非常大的分区范围内进行。

提前致谢

问候

dataframe apache-spark apache-spark-2.0

3
推荐指数
1
解决办法
4463
查看次数

在pandas groupby中合并两个列表并应用

我有一个数据框,例如:

    make     model     year range
0   Audi     A3        [1991, 1992, 1993]
1   Audi     A3        [1997, 1998]
Run Code Online (Sandbox Code Playgroud)

我需要:

    make     model     year range
0   Audi     A3        [1991, 1992, 1993, 1997, 1998]
Run Code Online (Sandbox Code Playgroud)

我试过了

df = df['year range].groupby([df.make, df.model]).apply(list).reset_index()
Run Code Online (Sandbox Code Playgroud)

但是,我最终将年份范围作为列表列表而不是单个列表。

看起来很简单,但我无法弄清楚!

python pandas

2
推荐指数
1
解决办法
2029
查看次数

re.fullmatch() 可以消除正则表达式中对字符串锚点的需要吗

考虑以下正则表达式,它检查密码强度。它具有开始和结束字符串锚点,以确保它匹配整个字符串。

pattern = re.compile(r'^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[$@$!%*#?&.])[A-Za-z\d$@$!%*#?&.]{8,}$')
    while True:
        user_pass = input('Enter a secure password: ')
        if re.fullmatch(pattern, user_pass):
            print('Successfully changed password')
            break
        else:
            print('Not secure enough. Ensure pass is 8 characters long with at least one upper and lowercase letter, number,'
                  ' and special character.')
Run Code Online (Sandbox Code Playgroud)

我注意到 Python 3.5 有一个 re.fullmatch() 似乎做同样的事情,但没有字符串锚点:

pattern = re.compile(r'(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[$@$!%*#?&.])[A-Za-z\d$@$!%*#?&.]{8,}')
while True:
    user_pass = input('Enter a secure password: ')
    if re.fullmatch(pattern, user_pass):
        print('Successfully changed password')
        break
    else:
        print('Not secure enough. Ensure pass is 8 characters long with at …
Run Code Online (Sandbox Code Playgroud)

python regex

1
推荐指数
1
解决办法
5403
查看次数

如何在 Pandas DataFrame 中获取具有非零最小值的第一行索引?

假设我有以下 Pandas DataFrame:

     U     A         B
0  2000    10       20
1  3000    40        0 
2  2100    20       30
3  2500     0       30 
4  2600    30       40
Run Code Online (Sandbox Code Playgroud)

如何获得 A 和 B 都具有非零值且 (A+B)/2 大于的第一行的索引 15

在这个例子中,我想得到,2因为它是具有非零 A 和 B 列的第一行,25其平均值大于15

请注意,此 DataFrame 很大,我正在寻找获取索引值的最快方法。

python pandas

1
推荐指数
1
解决办法
57
查看次数