【问题标题】:How to fix a "positional argument" in order to successfully run a census API for PostgreSQL?如何修复“位置参数”以成功运行 PostgreSQL 的人口普查 API?
【发布时间】:2019-09-12 01:39:04
【问题描述】:

我正在尝试从人口普查 API 变量的 csv 文件中提取数据,代码将选择所有州、县和人口普查区域。我收到“TypeError:state_county_tract()”; “需要 5 个位置参数,但给出了 6 个。”似乎返回了一个“(self, *args, **kwargs)”的包装函数。

我知道我的层次结构按“state_county_tract”顺序排列,并且我为每个使用通配符“(:*)”:stateFIPS、countyFIPS、tractFIPS。

```x = c.acs5.state_county_tract(mylist, stateFIPS, countyFIPS, tractFIPS, Census.ALL)  # mylist is a list of census variable names
```df = pd.DataFrame(x)
def main():
```df = pd.read_csv(r'C:\file.csv')
```mylist = df['Code'].values.tolist()
```tableName = 'acs2017'
```getData(mylist, tableName, 'census')
main() 

【问题讨论】:

    标签: sqlalchemy pycharm python-3.7 windows-10-desktop census


    【解决方案1】:
    ````for s in state_fips:
    ````````x = c.acs5.state_county_tract(mylist, s, county_fips, tract)  # mylist is a list 
    ````````of census variable names
    ````````df = pd.DataFrame(x)  # convert data to data frame
    ````````df.to_sql(tablename, engine, schema=schema, if_exists='append')
    
    ````def main():
    ````````df = pd.read_csv('list.csv', header=0, encoding='unicode_escape', sep=',', 
    ````````lineterminator='\n')
    ````````mylist = df['Code'].values.tolist()
    ````````tablename = '2017acs5'
    ````````getdata(mylist, tablename, 'census')
    
    ````main()
    You cant wildcard state, county, and tract. So I for loop the state_fips and wildcard county and tract
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多