使用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
满意答案
它使用默认的
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)
无法在WPF中更新我的数据网格(Trouble updating my datagrid in WPF)
简单的DataGrid绑定到远程SQL Server 2005/8数据库(Simple DataGrid Binding to Remote SQL Server 2005/8 Database)
如何以特定格式将日期和时间插入SQL Server数据库?(How Do I insert Date and Time into SQL Server database in certain format? [duplicate])
为什么此WPF数据网格显示从具有date数据类型的SQL Server数据库导入数据的时间?(Why is this WPF datagrid showing a time when importing data from SQL Server database with date datatype?)
日期格式化WPF数据网格(Date formatting WPF datagrid)
logparser TO_TIME输出与sql时间数据类型不匹配(logparser TO_TIME output not matching the sql time datatype)
将日期时间值插入SQL Server数据库(Insert date time value into SQL Server database)
将Wpf的datagrid绑定到数据库(binding datagrid for Wpf to a DB)
javascript - 如何从sql server数据库创建日期和时间的倒计时?(javascript - how to create countdown to date and time from sql server database?)
相关文章
更多企业级搜索引擎Solr 第三章 索引数据(Indexing Data)[1] (转)
Becoming a data scientist
Spring Data: a new perspective of data operations
data-config
(二)solr data import
《Big Data Glossary》笔记
TMF大数据分析指南 Unleashing Business Value in Big Data(一)
The Log: What every software engineer should know about real-time data's unifying abstraction
Solr4:配置Data Import,从数据库直接创建索引
Spring Data Solr教程(翻译)
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!