我从https://data.worldbank.org/indicator/AG.LND.AGRI.ZS?most_recent_value_desc=true下载了一个 csv 数据集, 其中 columns=["Country Name", "Country Code", "Indicator Name", "指示码","1960","1961","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971" ","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983", "1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007 ","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018","2019", "2020",] 我想用三列转置数据=[国家、年份、百分比]"2015","2016","2017","2018","2019","2020",] 我想用三列转置数据=[国家、年份、百分比]"2015","2016","2017","2018","2019","2020",] 我想用三列转置数据=[国家、年份、百分比]
在画面中,我将脚本放在数据之后
import pandas as pd
import numpy as np
def per_p(agri):
agri.drop(columns=["Country Code","Indicator Name","Indicator Code"],inplace=True)
agri_pivot=[]
year=agri.columns.tolist()[1:-1]
for ind in agri.index:
for y in year:
agri_pivot.append({'country':agri['Country Name'][ind],'year':y,'per':str(agri[y][ind])}) #
agri_pivot=pd.DataFrame(agri_pivot)
return agri_pivot
def get_output_schema():
return pd.DataFrame({
'country' : prep_string(),
'year' : prep_string(),
'per' : prep_string()#prep_decimal()
})
在 tableau prep 中有系统错误:Failure loading FedOp: D:\tc\work\maestro-2021-2\g_pc\modules\platform\tabcore\main\parser\DataValueParser.cpp|`anonymous-namespace'::TupleParser: :Parse|181 值 - 空文本
附言。每年列中的值是浮点数,但其中有缺失值,如果满足缺失值,prep 也会有错误(添加如果 np.isnan() 条件或使用 fillna() 也会有相同的错误消息)