【发布时间】:2021-05-07 23:36:07
【问题描述】:
我有两张桌子:
| reference_id | exclusiveness |
|---|---|
| 0047465 | luxury |
| 0165797 | luxury |
| 0013286 | selective |
| BB010 | selective |
| ticket-reference_id | product-reference_id |
|---|---|
| 2017010105521000016V | 47465 |
| 2017010105521000090V | 165797 |
| 2017010105521000111V | 13286 |
| 2017010105521000111V | BB010 |
对于这两个表我都使用了代码:
pd.read_csv('df1.csv', sep = ';')
pd.read_csv('df2.csv', sep = ';')
但在 product_reference_id 列的第二个表中,缺少零。 product_reference_id 和reference_id 列中的值必须相同。这样我就可以加入两个表。
【问题讨论】:
-
请提供预期的minimal, reproducible example (MRE)。它看起来好像您将一列读取为字符串,另一列读取为整数,但您没有为我们提供足够的上下文。
-
我已将这些列转换为字符串值。我需要的是列 product-reference_id 中的值与第一个表中的列 reference_id 中的值相同。但我不知道为什么 excel 加载此列时不带零。
-
我们也不知道,因为您还没有完成 MRE。请这样做;然后我们可以进行最终修复。
-
excel从哪里加载数据?它是从数据框本身(
df.to_excel)导出的吗? pandas 是否为列显示正确的数据类型 (df.dtypes)?
标签: python excel pandas csv read-data