df = pd.read_xlsx(r'C:\Users\17850\Desktop\data.xlsx')
时间: 2023-09-13 21:11:34 浏览: 236
这段代码有误,应该使用`pd.read_excel()`函数来读取 Excel 文件。另外,`\`在字符串中是转义符,需要使用双斜杠`\\`或者单斜杠`/`来表示路径。正确的代码如下:
```
import pandas as pd
df = pd.read_excel('C:/Users/17850/Desktop/data.xlsx')
```
相关问题
df = pd.read_excel(r'C:\Users\17850\Desktop\data.xlsx') ^ IndentationError: unexpected indent
这个错误通常是由于代码中存在缩进不当导致的。请检查前面的代码是否存在缩进,或者将这行代码前面的代码重新排版一下,使其缩进正确。正确的代码应该是这样的:
```
import pandas as pd
df = pd.read_excel(r'C:\Users\17850\Desktop\data.xlsx')
```
import pandas as pd df = pd.read_excel(r"C:\Users\asus\Desktop\用户账号情况统计表.xlsx") # 选择所属组织列和用户列 data = df[['用户账号', '姓名']] # 将内容转换为字典 organization_user_dict = data.set_index('用户账号')['姓名'].to_dict() print(organization_user_dict) df2 = pd.read_excel(r"C:\Users\asus\Desktop\人员分配企业岗位查询表.xlsx") print(df2)
这段代码使用 Pandas 库读取了两个 Excel 文件,并将第一个文件中的“用户账号”和“姓名”这两列内容转换为字典,其中“用户账号”列作为字典的键(key),“姓名”列作为字典的值(value)。然后,打印了转换后的字典内容。
接下来,又读取了第二个 Excel 文件,并将其内容保存在名为 `df2` 的 DataFrame 中,然后直接打印了 `df2` 的内容。
需要注意的是,这段代码中的 Excel 文件路径需要根据实际情况进行修改,确保能够正确读取到文件。
阅读全文
相关推荐
















