【发布时间】:2020-04-27 12:58:57
【问题描述】:
我使用 pd.read_csv 导入了一个 csv 文件,使用了 parse_dates 和 index_col。 这导致以下数据框
DatetimeIndex: 195972 entries, 2018-02-01 to 2019-10-25
Data columns (total 19 columns):
account_manager 195972 non-null object
article_des 195896 non-null object
article_n 195972 non-null object
article_o 195972 non-null object
budget_code 195972 non-null object
budget_naam 195972 non-null object
country 195972 non-null object
currency 195972 non-null object
customer 195972 non-null object
industrie 195972 non-null object
klantnaam 195972 non-null object
month 195972 non-null int64
revenue 195972 non-null float64
revenue_local 195972 non-null float64
sap_code 195972 non-null object
volume 195972 non-null float64
week 195972 non-null int64
weight 195972 non-null float64
year 195972 non-null int64
dtypes: float64(4), int64(3), object(12)
memory usage: 20.9+ MB
None
我已经尝试了所有可能的方法来从新数据框中的该数据框中仅选择一列(权重)。它们都不起作用。什么;在索引数据框中选择列的技巧是什么? 如果我在没有 index_col 的情况下导入 csv,我可以进行任何我想要的选择。
【问题讨论】:
-
使用 df[['weight']] 不起作用?
-
您可能正在处理空格。
df.to_dict()查看。然后做df.columns = df.columns.str.strip()修复。