我有一个叫做'my_class'放入的课程'my_module'.我需要导入这个类.我试着这样做:
import importlib
result = importlib.import_module('my_module.my_class')
Run Code Online (Sandbox Code Playgroud)
但它说:
ImportError: No module named 'my_module.my_class'; 'my_module' is not a package
Run Code Online (Sandbox Code Playgroud)
所以.我可以看到它只适用于模块,但不能处理类.如何从模块导入类?
我在熊猫中有数据框:
In [10]: df
Out[10]:
col_a col_b col_c col_d
0 France Paris 3 4
1 UK Londo 4 5
2 US Chicago 5 6
3 UK Bristol 3 3
4 US Paris 8 9
5 US London 44 4
6 US Chicago 12 4
Run Code Online (Sandbox Code Playgroud)
我需要统计独特的城市.我可以数独特的状态
In [11]: df['col_a'].nunique()
Out[11]: 3
Run Code Online (Sandbox Code Playgroud)
我可以尝试数独特的城市
In [12]: df['col_b'].nunique()
Out[12]: 5
Run Code Online (Sandbox Code Playgroud)
但这是错误的,因为法国的美国巴黎和巴黎是不同的城市.所以现在我这样做:
In [13]: df['col_a_b'] = df['col_a'] + ' - ' + df['col_b']
In [14]: df
Out[14]:
col_a col_b col_c col_d col_a_b
0 France Paris …Run Code Online (Sandbox Code Playgroud) 我不确定我的问题是否正确,但我不知道如何解释它。所以我有一些清单,比如
a = ['11', '12']
b = ['21', '22']
c = ['31', '32']
Run Code Online (Sandbox Code Playgroud)
我需要得到类似的东西:
result = [
['11', '21', '31'],
['11', '21', '32'],
['11', '22', '31'],
['11', '22', '32'],
['12', '21', '31'],
['12', '21', '32'],
['12', '22', '31'],
['12', '22', '32']
]
Run Code Online (Sandbox Code Playgroud) 有没有办法使用 Google Sheets API 在 Google Sheets 中自动调整列宽?我只能找到DimensionProperties但它需要精确的值 n 像素。
我有一项任务是在收到WebHook时将行添加到Google表格中.现在我正在尝试设置IFTTT,但有一些问题它说我应该使用URL https://maker.ifttt.com/trigger/{event}/with/key/{my_key},这是可以的,我可以做到这一点.但它需要在请求中发送一些数据,并且我的系统可以做到的唯一方法是将它附加到查询字符串中https://maker.ifttt.com/trigger/{event}/with/key/{my_key}?name1=Alex&name2=Helen
但IFTTT没有看到我的数据.它说它可以看到附加JSON中的数据,但我不能使用JSON.
那么有没有办法将我的数据传递给查询字符串或shell中的IFTT我忘了IFTTT并调查如何直接连接到Google Sheet?
我在 VSCode 中有一个 Python 项目。其结构
root
+-- docs
+-- some_other_folder
+-- src
+-- app
| +-- main.py
+-- tests
+-- conftest.py
Run Code Online (Sandbox Code Playgroud)
conftest.py 有进口
from app.main import app
Run Code Online (Sandbox Code Playgroud)
我的任务是设置src为根文件夹,否则我会收到警告Import 'app.main' could not be resolved
我有一个网页,其中包含一些我想要提取的数据,因此我打开 Chrome 开发者控制台并输入:
$x('//a[contains(@class, "link-class")]/text()')
Run Code Online (Sandbox Code Playgroud)
但我有:
[text, text, text]
Run Code Online (Sandbox Code Playgroud)
而不是字符串列表。有没有可以获取可以复制到记事本、Excel 等的字符串列表?
我的Google表格中有一些脚本/完成所有这些脚本可能要花很多时间(我认为最多需要5分钟)。我想显示一些消息,用户应该稍等一下。所以我有一些类似的代码:
function test(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange("A1");
sheet.clear();
cell.setValue('WAIT!!!!');
DATA = UrlFetchApp.fetch(url);
// And some action that takes a lot of time ....
cell.setValue('DONE!!!!');
Run Code Online (Sandbox Code Playgroud)
但是它不会显示“ WAIT”,而在一切正常的情况下只会显示“ DONE”。如果出现任何错误并且功能崩溃,它只能显示“ WAIT”。看来我需要以某种方式刷新它。
我有200000行的数据帧.每条记录都有一个时间戳,我需要按日期对它们进行分组.所以我这样做:
In [67]: df['result_date'][0]
Out[67]: Timestamp('2017-09-01 09:12:00')
In [68]: %timeit df['result_day'] = df['result_date'].apply(lambda x: str(x.date()))
2.26 s ± 73.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [69]: df['result_day'][0]
Out[69]: '2017-09-01'
Run Code Online (Sandbox Code Playgroud)
要么
In [70]: %timeit df['result_day'] = df['result_date'].apply(lambda x: x.date())
2.05 s ± 213 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [71]: df['result_day'][0]
Out[71]: datetime.date(2017, 9, 1)
Run Code Online (Sandbox Code Playgroud)
无论如何,它需要约2秒.我可以更快地完成吗?
UPD:
In [75]: df.shape
Out[75]: (228217, 18)
In [77]: …Run Code Online (Sandbox Code Playgroud) python ×4
dataframe ×2
pandas ×2
datetime ×1
group-by ×1
ifttt ×1
javascript ×1
pyright ×1
python-3.x ×1