## 获取数据 from sklearn.metrics import r2_score import statsmodels.api as sm import numpy as np import pandas as pd import matplotlib.pyplot as plt data = pd.read_table('C:/Users/lb/Desktop/test/k-means_data.txt',sep='\t',engine="python",encoding = 'gbk') data.columns.values data.head()改为读取csv文件
时间: 2024-02-20 21:59:30 浏览: 112
import pandas as pd.docx
可以使用`pd.read_csv()`函数读取csv文件。将代码中的`pd.read_table()`替换为`pd.read_csv()`,同时指定`delimiter`参数为逗号(默认值即为逗号),即可读取csv文件。下面是修改后的代码:
```python
from sklearn.metrics import r2_score
import statsmodels.api as sm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('C:/Users/lb/Desktop/test/k-means_data.txt', delimiter=',', encoding='gbk')
data.columns.values
data.head()
```
阅读全文