简体   繁体   English

使用 pyMannKendall python package 测试网格降雨数据的趋势

[英]Using pyMannKendall python package for testing the trend for gridded rainfall data

I am using pyMannKendall python package for testing the trend for gridded rainfall data.我正在使用pyMannKendall python package 来测试网格降雨数据的趋势。 I am successful in carrying out trend analysis for all the grids but now I want to write the results of all the grids to a CSV file.我成功地对所有网格进行了趋势分析,但现在我想将所有网格的结果写入一个 CSV 文件。 I am new to coding and is facing a problem.我是编码新手,正面临一个问题。 Attached below is my code.下面附上我的代码。

import pymannkendall as mk
import csv
import numpy as np

df = pd.read_csv("pr_1979_2018.csv", index_col = "Year")

for i in df.columns:

    res = mk.hamed_rao_modification_test(df[i])

    new_df=pd.DataFrame(data=a, index= ['trend','h','p','z', 'Tau', 
    's','var_s','slope', 'intercept'], columns=['stats'], dtype=None)

new_df.to_csv("Mk_2.csv")

On running this code I am getting only a single column in my CSV file, however I want results of all the columns in my resulting CSV file.运行此代码时,我在 CSV 文件中只得到一列,但是我想要生成的 CSV 文件中所有列的结果。 Please help请帮忙

You can convert your rows into columns in Python using Transpose() in Pandas before export.您可以在导出前使用 Pandas 中的Transpose()将行转换为 Python 中的列。

Try this:尝试这个:

new_df = pd.DataFrame.transpose(new_df)

new_df.to_csv("Mk_2.csv",header=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM