pandas报错AttributeError: 'dict' object has no attribute 'shape'
时间: 2023-09-28 09:12:34 浏览: 1251
pandas报错AttributeError: 'dict' object has no attribute 'shape'说明在使用pandas时,对一个字典对象进行了shape操作,而字典对象并没有shape属性。这个错误可以通过将字典对象转换为DataFrame对象来解决。你可以使用pd.DataFrame()函数将字典转换为DataFrame对象,然后再进行shape操作。例如,你可以按照以下方式修改你的代码来解决这个问题:
```
import pandas as pd
# 假设你的字典名为data
data = {'测试1': [1, 2, 3], '测试2': [4, 5, 6]}
# 将字典转换为DataFrame对象
df = pd.DataFrame(data)
# 打印DataFrame的形状
print(df.shape)
```
这样,你就不会再遇到AttributeError: 'dict' object has no attribute 'shape'的错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [[已解决]Pands里面报AttributeError: type object ‘object‘ has no attribute ‘dtype](https://blog.csdn.net/m0_57021623/article/details/129774480)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文