import csv
import os
import pandas as pd
os.chdir('C:\\Users\\khalha\\Desktop\\RealExcel')
filename = 'sales.csv'
Sales = pd.read_csv('sales.csv')
iFlow = Sales.loc[Sales['Product'].str.contains('Vector HF/LF (Opt 2)',
na=False), "18-Jun"]
print(iFlow)
MaySales = pd.read_csv('maysales.csv')
iFlowmay = MaySales.loc[MaySales['Product'].str.contains('Vector HF/LF (Opt
2)', na=False), "18-Jun"]
print(iFlowmay)
我收到错误消息:
C:\Users\khalha\eclipse-workspace\hariskk\hey\hello.py:8: UserWarning: This pattern has match groups. To actually get the groups, use str.extract. iFlow = Sales.loc[Sales['Product'].str.contains('Vector HF/LF (Opt 2)', na=False), "18-Jun"] Series([], Name: 18-Jun, dtype: object) C:\Users\khalha\eclipse-workspace\hariskk\hey\hello.py:12: UserWarning: This pattern has match groups. To actually get the groups, use str.extract. iFlowmay = MaySales.loc[MaySales['Product'].str.contains('Vector HF/LF (Opt 2)', na=False), "18-Jun"] Series([], Name: 18-Jun, dtype: object)
此代码适用于第一个块,但是当我添加Maysales部分时,它将停止工作。
答案 0 :(得分:0)
搜索包含括号的文本时,Python会感到困惑。由于您正在导入数据框,因此我不能只运行您的代码,但是我想是否可以:
iFlow = Sales.loc[Sales['Product'].str.contains('\Vector HF/LF (Opt 2', na=False), "18-Jun"]
它将起作用