'list' object has no attribute 'to'
时间: 2023-10-05 09:10:29 浏览: 138
Python 从attribute到property详解
当你遇到错误"'list' object has no attribute 'to'"时,这意味着你使用的对象是一个列表,而列表没有名为"to"的属性。
要解决这个问题,你可以使用pandas库中的DataFrame属性。首先,你需要将你的列表转换为DataFrame对象。你可以使用以下代码完成这一步骤:
```
import pandas as pd
my_list = [[1,2,3],[4,5,6],[7,9,9]]
df = pd.DataFrame(my_list)
```
然后,你可以使用DataFrame对象的"to_csv"方法将其转存为CSV文件:
```
df.to_csv('path/to/myfile.csv', index=False)
```
其中,"path/to/myfile.csv"是你想要将CSV文件保存的路径。设置"index=False"参数可以避免在CSV文件中包含行索引。
这样,你就能够成功将列表转存为CSV文件,而不再遇到"'list' object has no attribute 'to'"错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [关于tensor类型数据却报错‘list‘ object has no attribute ‘to](https://blog.csdn.net/littleiittlehh/article/details/118339919)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [python报错: list object has no attribute shape的解决](https://download.csdn.net/download/weixin_38748721/13708867)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Python将list元素转存为CSV文件](https://blog.csdn.net/qq_38268886/article/details/80744721)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文