使用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)[2022-10-23]
不要忘记使用DataGrid.Columns,所有列必须在该集合内。 在我的项目中,格式日期有点不同: -
您没有设置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
() ... -
简单的DataGrid绑定到远程SQL Server 2005/8数据库(Simple DataGrid Binding to Remote SQL Server 2005/8 Database)[2022-02-07]
那么,如果你想使用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) try ... -
而不是连接您的sql命令文本,使用参数化查询。 它不仅可以保护您免受sql注入,而且还使用强类型参数(例如,参数应该具有SqlDbType.DateTime类型来传递datetime值),因此问题将消失。 var cm = new SqlCommand("Insert into Orders (Order_number, Phone, DateTime) values (@OrderNumber, @Phone, @DateTime)"); cm.Parameters.Add("@OrderNumber", ...
-
它使用默认的DateTime表示,它在您的系统中来自您的线程当前文化。 如果要更改它,则应手动派生列(使用DataGridTemplateColumn,并在CellTemplate使用它):
It uses default DateTime representation, which in your system, comes from your thread ... -
日期格式化WPF数据网格(Date formatting WPF datagrid)[2022-07-02]
“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'll ne ... -
logparser TO_TIME输出与sql时间数据类型不匹配(logparser TO_TIME output not matching the sql time datatype)[2024-02-02]
不幸的是,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 TIME c ... -
您的代码相当于: 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 = MyDTP01 ...
-
问题不在于数据绑定本身。 看起来,在配置文件或ConnectionStrings []中使用的密钥中都有一个输入错误。 如果你在这里发布stacktrace的整个错误,这将会很有用。 PS您的配置文件中存在拼写错误。 它不应该假设你的日期时间你得到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 Date(); ...
相关文章
更多- 企业级搜索引擎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教程(翻译)
最新问答
更多- 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
- Java中的不可变类(Immutable class in Java)
- 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
- linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
- Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
- 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
- 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
- Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
- EXCEL VBA 基础教程下载
- RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
- 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
- JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
- mysql 关于分组查询、时间条件查询
- 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
- Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
- 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
- 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
- 使用前端框架带来哪些好处,相对于使用jquery
- Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
- 高考完可以去做些什么?注意什么?
- 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
- 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
- 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
- R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
- Allauth不会保存其他字段(Allauth will not save additional fields)
- python中使用sys模块中sys.exit()好像不能退出?
- 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
- 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
- sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
- 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)