使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)

我正在尝试编写一个程序来计算指定日期和时间内的平均压力,温度和湿度......但不确定为什么我会得到'nan'值...? 这是我的代码:任何想法?

import pandas as pd
import numpy as np

df = pd.DataFrame.from_csv('C:\Users\Joey\Desktop\Python\CSV\TM4CVC.csv',index_col = None)

df2 = pd.DataFrame({'temp':df['Ch1_Value'],
'press':df['Ch2_Value'],
    'humid':df['Ch3_Value'], 'Date' : df['Date'], 'Time' : df['Time']})

df2['DateTime'] = pd.to_datetime(df2.apply(lambda x: x['Date']+ ' '+ x['Time'], 1))

df2.index = pd.to_datetime(df2.pop('DateTime'))

df3 = df2.drop(['Date', 'Time'], 1)

#------------------------------------------------------------------------------

def TempPressHumid(datetime_i, datetime_e):

    index = df3[datetime_i:datetime_e]

    out = {'temp_avg':np.mean(index['temp']),
    'temp_std':np.std(index['temp']),
    'press_avg':np.mean(index['press']),
    'press_std':np.std(index['press']),
    'humid_avg':np.mean(index['humid']),
    'humid_std':np.std(index['humid'])}
    print out


TempPressHumid(datetime_i = '2012-06-25 08:27:19', datetime_e = '2012-01-25 10:59:33')

我的输出是:

{'humid_std': nan, 'press_std': nan, 'humid_avg': nan, 'temp_avg': nan, 'temp_std': nan, 'press_avg': nan}

print df3给了我:

                      humid  press  temp
DateTime                                
2012-06-25 08:21:19  1004.0   21.2  26.0
2012-06-25 08:22:19  1004.0   21.2  26.0
2012-06-25 08:23:19  1004.1   21.3  26.0
-----------------------------------------

等等...


I'm trying to write a program that will compute the average press, temp and humidity within a specified date and time.... but not sure why im getting 'nan' values... ? here is my code: any ideas?

import pandas as pd
import numpy as np

df = pd.DataFrame.from_csv('C:\Users\Joey\Desktop\Python\CSV\TM4CVC.csv',index_col = None)

df2 = pd.DataFrame({'temp':df['Ch1_Value'],
'press':df['Ch2_Value'],
    'humid':df['Ch3_Value'], 'Date' : df['Date'], 'Time' : df['Time']})

df2['DateTime'] = pd.to_datetime(df2.apply(lambda x: x['Date']+ ' '+ x['Time'], 1))

df2.index = pd.to_datetime(df2.pop('DateTime'))

df3 = df2.drop(['Date', 'Time'], 1)

#------------------------------------------------------------------------------

def TempPressHumid(datetime_i, datetime_e):

    index = df3[datetime_i:datetime_e]

    out = {'temp_avg':np.mean(index['temp']),
    'temp_std':np.std(index['temp']),
    'press_avg':np.mean(index['press']),
    'press_std':np.std(index['press']),
    'humid_avg':np.mean(index['humid']),
    'humid_std':np.std(index['humid'])}
    print out


TempPressHumid(datetime_i = '2012-06-25 08:27:19', datetime_e = '2012-01-25 10:59:33')

My output is:

{'humid_std': nan, 'press_std': nan, 'humid_avg': nan, 'temp_avg': nan, 'temp_std': nan, 'press_avg': nan}

print df3 gives me:

                      humid  press  temp
DateTime                                
2012-06-25 08:21:19  1004.0   21.2  26.0
2012-06-25 08:22:19  1004.0   21.2  26.0
2012-06-25 08:23:19  1004.1   21.3  26.0
-----------------------------------------

etc...


原文:https://stackoverflow.com/questions/28109673
2024-04-24 18:04

满意答案

它使用默认的DateTime表示,它在您的系统中来自您的线程当前文化。

如果要更改它,则应手动派生列(使用DataGridTemplateColumn,并在CellTemplate使用它):

<Textbox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" />

It uses default DateTime representation, which in your system, comes from your thread current culture.

If you want to change it, you should derive your columns manually (use DataGridTemplateColumn, and use this in your CellTemplate):

<Textbox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" />

相关问答

更多

WPF数据网格中的日期格式(Date formatting in WPF datagrid)

不要忘记使用DataGrid.Columns,所有列必须在该集合内。 在我的项目中,格式日期有点不同: <tk:DataGrid> <tk:DataGrid.Columns> <tk:DataGridTextColumn Binding="{Binding StartDate, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}" /> </tk:DataGrid.Columns> </tk:DataGrid> 使用AutoGenerate...

无法在WPF中更新我的数据网格(Trouble updating my datagrid in WPF)

您没有设置Quote_ID参数。 所以你的更新它可能运行WHERE Quote_ID = null所以没有更新。 using LINQ I was able to resolve the issue. Here's the code: var sqtmDC = new SqtmLinqDataContext(); var mainTable = from generalInfo in sqtmDC.GetTable<General_Info>() ...

简单的DataGrid绑定到远程SQL Server 2005/8数据库(Simple DataGrid Binding to Remote SQL Server 2005/8 Database)

那么,如果你想使用Linq2Sql(比EntityFramework更难学习)尝试一下这样的教程: http : //www.codeproject.com/KB/WPF/WPFDataGrid.aspx 或http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx 你会做得很好。 Well, if you want to use Linq2Sql (less difficult to learn than EntityFramework)...

如何以特定格式将日期和时间插入SQL Server数据库?(How Do I insert Date and Time into SQL Server database in certain format? [duplicate])

而不是连接您的sql命令文本,使用参数化查询。 它不仅可以保护您免受sql注入,而且还使用强类型参数(例如,参数应该具有SqlDbType.DateTime类型来传递datetime值),因此问题将消失。 var cm = new SqlCommand("Insert into Orders (Order_number, Phone, DateTime) values (@OrderNumber, @Phone, @DateTime)"); cm.Parameters.Add("@OrderNum...

为什么此WPF数据网格显示从具有date数据类型的SQL Server数据库导入数据的时间?(Why is this WPF datagrid showing a time when importing data from SQL Server database with date datatype?)

它使用默认的DateTime表示,它在您的系统中来自您的线程当前文化。 如果要更改它,则应手动派生列(使用DataGridTemplateColumn,并在CellTemplate使用它): <Textbox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" /> It uses default DateTime representation, which in your system, comes from your th...

日期格式化WPF数据网格(Date formatting WPF datagrid)

“date”Sql类型最终成为数据集中的DateTime,这也是您获得时间的原因。 您需要定义列并在数据网格上指定格式。 编辑:我错了无法格式化自动生成列时。 正如在这里提到的其他答案一样,这个问题: 需要在动态构建的WPF DataGrid地址中设置格式的日期以实现这一点。 The "date" Sql type ends up being a DateTime in your dataset, which is why you're getting the time as well. You'...

logparser TO_TIME输出与sql时间数据类型不匹配(logparser TO_TIME output not matching the sql time datatype)

不幸的是,LogParser不支持时间类型。 您可以尝试将DATE和TIME列作为单个Datetime一起发送,或者将TIME列作为字符串发送,并希望SQL服务器将其转换为Time ... Unfortunately no, LogParser does not support a time-of-day type. You may try to send your DATE and TIME columns together as a single Datetime, or send the T...

将日期时间值插入SQL Server数据库(Insert date time value into SQL Server database)

您的代码相当于: var parameter = new SqlParameter("@mydate", SqlDbType.DateTime); var value = MyDTP01.Value; parameter.Value = value; cmd.Parameters.Add(value); 您想要添加参数 ,而不是值。 所以: cmd.Parameters.Add(new SqlParameter("@mydate", SqlDbType.DateTime)).Value = My...

将Wpf的datagrid绑定到数据库(binding datagrid for Wpf to a DB)

问题不在于数据绑定本身。 看起来,在配置文件或ConnectionStrings []中使用的密钥中都有一个输入错误。 如果你在这里发布stacktrace的整个错误,这将会很有用。 PS您的配置文件中存在拼写错误。 它不应该 <connectionStrings> <add name="ConString" connectionString="Data Source=MYDataSB\SQLExpress; User Id=sa;Password=gm03C3; I...

javascript - 如何从sql server数据库创建日期和时间的倒计时?(javascript - how to create countdown to date and time from sql server database?)

假设你的日期时间你得到int tbl_Event.StartDate + tbl_Event.StartTime = 2017-02-17 10:45:00 这将是你的.. var ServerDate_Time = '2017-02-17 10:45:00'; console.log(CompareDateTime(ServerDate_Time)); function CompareDateTime (ServerDateTime){ var dateString = new Dat...

相关文章

更多

企业级搜索引擎Solr 第三章 索引数据(Indexing Data)[1] (转)

Index Data Author: David Smiley Eric Pugh 译者:Koala+ ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

data-config

Data-config为solr的data-import处理器配置数据来源。 依次按照如下树状结构: ...

(二)solr data import

solr 的 data import 导入 mysql数据 (1)、编辑 example/solr/c ...

《Big Data Glossary》笔记

清明假期翻以前的笔记发现有一些NoSQL相关的内容,比较零散,是之前读《Big Data Glossa ...

TMF大数据分析指南 Unleashing Business Value in Big Data(一)

大数据分析指南 TMF Frameworx最佳实践 Unleashing Business Value ...

Solr4:配置Data Import,从数据库直接创建索引

1. 要求 将数据库中的数据直接创建到Solr索引中去。先做全部索引,然后定期做增量索引。 2. 环 ...

Spring Data Solr教程(翻译)

大多数应用都必须具有某种搜索功能,问题是搜索功能往往是巨大的资源消耗并且它们由于沉重的数据库加载而拖垮 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本