在numpy计算中按日期分隔数据

时间:2020-07-22 22:25:33

标签: python-3.x pandas numpy

我想每天对数据集进行一次计算 这是csv文件: enter image description here

holteandtalley软件包需要numpy值,这样做似乎忽略了日期是一回事。考虑日期会怎样?转换为numpy值怎么可能???会成为for循环的for 1/1/2015-> 1/2/2015吗?

           <script>
var buyBtn = document.getElementById('payButton');
var responseContainer = document.getElementById('paymentResponse');

// Create a Checkout Session with the selected product
var createCheckoutSession = function (stripe) {
    return fetch("stripe_charge.php", {
         method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
        checkoutSession: 1,
    }),
}).then(function (result) {
        return result.json();
});
};

// Handle any errors returned from Checkout
 var handleResult = function (result) {
if (result.error) {
    responseContainer.innerHTML = '<p>'+result.error.message+'</p>';
}
buyBtn.disabled = false;
buyBtn.textContent = 'Buy Now';
};

// Specify Stripe publishable key to initialize Stripe.js
var stripe = Stripe('<?php echo STRIPE_PUBLISHABLE_KEY; ?>');

buyBtn.addEventListener("click", function (evt) {
    buyBtn.disabled = true;
buyBtn.textContent = 'Please wait...';

createCheckoutSession().then(function (data) {
    if(data.sessionId){
        stripe.redirectToCheckout({
            sessionId: data.sessionId,
        }).then(handleResult);
    }else{
        handleResult(data);
    }
});
});
</script>

e以上表示从csv文件复制的一小部分数据示例。我有3分钟的平均数据,而且很多。

但目标是每天进行h计算,然后将其保存到csv文件中!

data = '''Date_minute   pressure_minute temperature_minute  _salinity_minute    density_minute
 1/1/2015 1:00  190.7204494 4.404067416 34.91503019 1028.562223
1/1/2015 1:03   226.7342222 4.380520556 34.9135466  1028.730406
1/1/2015 1:06   275.7265    4.362583889 34.91181953 1028.95763
1/2/2015 19:36  2509.618056 2.28284 34.88852093 1039.350304
1/2/2015 19:39  2541.392889 2.150881111 34.8855637  1039.508935
1/2/2015 19:42  2564.401333 1.961558889 34.88407401 1039.637896
1/2/2015 19:45  2589.747    1.865299444 34.88299396 1039.763993
1/2/2015 19:48  2605.054929 1.83268 34.88257996 1039.836633
1/3/2015 13:00  2600.003539 2.152193258 34.88413074 1039.76865
1/3/2015 13:03  2564.831611 2.343941111 34.88770727 1039.586481
1/3/2015 13:06  2516.2825   2.562826111 34.89977395 1039.347239
1/3/2015 13:09  2467.989611 2.644409444 34.90447681 1039.123766
1/3/2015 13:12  2419.898056 2.702593889 34.90656564 1038.902537
1/3/2015 13:15  2372.020838 2.764951955 34.90882427 1038.681659'''

enter image description here

2 个答案:

答案 0 :(得分:0)

如果使用df['data'] = df['data'].strftime('%Y%m%d%H%M').astype(int)将日期格式更改为整数怎么办?如果您的数据不是pandas datetime格式,那么您还需要第一行代码为:df['data'] = pd.to_datetime(df['data'], dayfirst=True)

df['data'] = pd.to_datetime(df['data'], dayfirst=True)
df['data'] = df['data'].strftime('%Y%m%d%H%M').astype(int)

答案 1 :(得分:0)

实际上,您不必将其转换为numpy,但必须将Pandas Series转换为listThe source code 显示传入的参数由asarray转换。