Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何传递带有错误的列:必须使用某种类型的集合调用索引(…),在python中传递了时间戳(';2021-03-02 05:45:42';)_Python_Pandas_Csv - Fatal编程技术网

如何传递带有错误的列:必须使用某种类型的集合调用索引(…),在python中传递了时间戳(';2021-03-02 05:45:42';)

如何传递带有错误的列:必须使用某种类型的集合调用索引(…),在python中传递了时间戳(';2021-03-02 05:45:42';),python,pandas,csv,Python,Pandas,Csv,我想创建一个折线图,根据指定的关键字变量显示内容。我是通过获取csv文件中的数据实现的,该文件包含以下列:关键字、日期、Tweet、情绪。当我使用if函数检查Keyword=字段(指定的关键字变量)的内容时,我得到一个错误: TypeError:必须使用某种类型的集合调用索引(…),传递了时间戳('2021-03-02 05:45:42') 我不知道我需要修理哪一部分。 这是我的密码: query = "bali" df = pd.read_csv('tes3.csv', h

我想创建一个折线图,根据指定的关键字变量显示内容。我是通过获取csv文件中的数据实现的,该文件包含以下列:关键字、日期、Tweet、情绪。当我使用if函数检查Keyword=字段(指定的关键字变量)的内容时,我得到一个错误:

TypeError:必须使用某种类型的集合调用索引(…),传递了时间戳('2021-03-02 05:45:42')

我不知道我需要修理哪一部分。 这是我的密码:

query = "bali"
df = pd.read_csv('tes3.csv', header=None, 
                 names=["Keyword", "Date", "Tweet", "Sentimen"])
df['Date'] = pd.to_datetime(df['Date'], errors='coerce')


for index, row in df.iterrows():
    if row['Keyword']==query:
        result = row.groupby([pd.Grouper(key='Date', freq='3s'), 'Sentimen']).count().unstack(fill_value=0).stack().reset_index()
        

我认为这里不需要循环,通过过滤然后使用
groupby

mask = df['Keyword']==query
result = df[mask].groupby([pd.Grouper(key='Date', freq='3s'), 'Sentimen']).count().unstack(fill_value=0).stack().reset_index()

哦,我的上帝,你是对的!!!!多谢各位