我知道我的代码是超级不整洁,可能看起来很可怕,但作为甚至不是业余的,我试图创建简单的代码,让我看到计划关闭的特定高速公路。我每天都能抽出我想要的表格和专栏。我现在唯一的问题是只显示以“M5”和“M6”字符串开头的行。我尝试了.str.startwith(“M6”),但总是给我一个错误。也尝试实现.str.contains,效果相同。
from datetime import datetime
import pandas as pd
url = 'https://nationalhighways.co.uk/media/s2pjwbuk/7-day-closure-report-26-july-web-upload.xls'
dt = datetime.now()
x = dt.weekday()
column_name = [5]
print(x)
if x == 0:
sheet_name = "Monday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
if x == 1:
sheet_name = "Tuesday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
if x == 2:
sheet_name = "Wednesday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
if x == 3:
sheet_name = "Thursday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
if x == 4:
sheet_name = "Friday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
if x > 4:
sheet_name = "Monday"
data = pd.read_excel(url, sheet_name, usecols=column_name)
print(data)
字符串
数据= pd.read_excel(url,sheet_name,usecols=column_name.str.startwith(“M6”))
或者是
print(data.str.contains“M6”)
1条答案
按热度按时间9nvpjoqh1#
你可以在函数链中使用.query():
代码:
字符串
输出量:
型