首页 > 解决方案 > Python数据框第一列偏移量

问题描述

我正在使用 python 调用 API 并将其加载到数据框中,非常简单的代码:

import simfin as sf
import pandas as pd
import numpy as np

# Set your SimFin+ API-key for downloading data.
sf.set_api_key('free')

# Set the local directory where data-files are stored.
# The directory will be created if it does not already exist.
sf.set_data_dir('~/simfin_data/')

df_industries = sf.load_industries()

print(df_industries)

问题是输出具有第一列标题偏移量,当我将此数据加载到 powerBI 时,它会忽略第一列:

                     Sector                    Industry
IndustryId
100001          Industrials         Industrial Products
100002          Industrials           Business Services
100003          Industrials  Engineering & Construction
100004          Industrials            Waste Management
100005          Industrials     Industrial Distribution
...                     ...                         ...
110004      Basic Materials             Metals & Mining
110005      Basic Materials          Building Materials
110006      Basic Materials                        Coal
110007      Basic Materials                       Steel
111001                Other        Diversified Holdings

我应该如何让第一列与其他列保持相同的对齐方式,以使其正确导入到 powerBI 中。

标签: pythonpandaspowerbi-desktoppowerbi-datasource

解决方案


推荐阅读