小编24h*_*ast的帖子

将通配符应用于 Pandas isin 过滤器

总菜鸟在这里,对不起初学者的问题。我一直在 Pandas 中绞尽脑汁,试图过滤 Dataframe 中的一个系列,以定位包含字符串列表中的一个的行。

import pandas as pd
streets = ['CONGRESS', 'GUADALUPE', 'BEN WHITE', 'LAMAR', 'MANCHACA', 'BURNET', 'ANDERSON', 'BRAKER' ]
# the actual list of street names is much longer than this

strs = pd.read_csv('short_term_rental_locations.csv')

# the following returns no values, or all 'False' values to be more accurate
strs[strs['PROP_ADDRESS'].isin(streets)]

# but if I use .contains, i can find rows that contain part of the 
# street names, but .contains has a limit of six positional arguments.
strs[strs['PROP_ADDRESS'].str.contains('CONGRESS')]
Run Code Online (Sandbox Code Playgroud)

我试过在 …

python string series dataframe pandas

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

努力在Python中将时区GMT转换为CST

我花了几个小时在这上面,但我的大脑似乎无法弄清楚,而且我发现的很多信息似乎都适用于 Python 2?

import datetime as dt
from datetime import datetime
from pytz import timezone
import pytz
time_stamp = 'Mon, 17 Dec 2018 18:05:01 GMT'

central = timezone('US/Central')
published_time = datetime.strptime(time_stamp, '%a, %d %b %Y %H:%M:%S %Z')
published_cst = published_time.astimezone(central)
actual_time_published = published_cst.strftime('%a, %b %d %Y at %I:%M:%S %p %Z')




print(time_stamp)
print(published_time)
print(published_cst)
print(actual_time_published)
Run Code Online (Sandbox Code Playgroud)

预计 acutal_time_published 为 CST,因为published_cst 有 GMT-6 小时(第三个结果),但这里是每个打印命令的实际结果。

Mon, 17 Dec 2018 18:05:01 GMT
2018-12-17 18:05:01
2018-12-17 18:05:01-06:00
Mon, Dec 17 2018 at 06:05:01 PM CST
Run Code Online (Sandbox Code Playgroud)

拔我的头发! …

python timezone datetime pytz python-3.x

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

标签 统计

python ×2

dataframe ×1

datetime ×1

pandas ×1

python-3.x ×1

pytz ×1

series ×1

string ×1

timezone ×1