python - 如何使用 pandas 在 python 中重塑 csv 文件?
问题描述
我正在尝试在 python 中重塑这个 csv 文件,使其具有 1,000 行和所有 12 列,但它只显示为一列
我试过使用 df.iloc[:][:1000] 将它缩短到 1000 行,但它仍然只给我 1 列
Wine 的数据框
df_w= pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv')
df_w= df_w.iloc[:12][:1000]
df_w
显示的数据框是 1000 行,只有 1 列,我想知道如何将数据设置到其各自的列标题中
解决方案
使用sep=';'
, 作为分号分隔符:
df_w= pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv', sep=';')
df_w= df_w.iloc[:12][:1000]
df_w
输出:
fixed acidity volatile acidity citric acid residual sugar chlorides free sulfur dioxide total sulfur dioxide density pH sulphates alcohol quality
0 7.4 0.70 0.00 1.9 0.076 11.0 34.0 0.9978 3.51 0.56 9.4 5
1 7.8 0.88 0.00 2.6 0.098 25.0 67.0 0.9968 3.20 0.68 9.8 5
2 7.8 0.76 0.04 2.3 0.092 15.0 54.0 0.9970 3.26 0.65 9.8 5
3 11.2 0.28 0.56 1.9 0.075 17.0 60.0 0.9980 3.16 0.58 9.8 6
4 7.4 0.70 0.00 1.9 0.076 11.0 34.0 0.9978 3.51 0.56 9.4 5
5 7.4 0.66 0.00 1.8 0.075 13.0 40.0 0.9978 3.51 0.56 9.4 5
6 7.9 0.60 0.06 1.6 0.069 15.0 59.0 0.9964 3.30 0.46 9.4 5
7 7.3 0.65 0.00 1.2 0.065 15.0 21.0 0.9946 3.39 0.47 10.0 7
8 7.8 0.58 0.02 2.0 0.073 9.0 18.0 0.9968 3.36 0.57 9.5 7
9 7.5 0.50 0.36 6.1 0.071 17.0 102.0 0.9978 3.35 0.80 10.5 5
10 6.7 0.58 0.08 1.8 0.097 15.0 65.0 0.9959 3.28 0.54 9.2 5
11 7.5 0.50 0.36 6.1 0.071 17.0 102.0 0.9978 3.35 0.80 10.5 5
推荐阅读
- reactjs - 如何使单个 React Docker 构建/映像在所有环境中运行?
- vb.net - 在 VB.NET 中禁用表单的默认实例
- swift - swift 4选择器执行多个参数
- sql - Postgres Select Query - 对相同的对象进行分组
- java-8 - 正在获取 LiquiBase 变更集,但未显示在 databasechangelog 或数据库中
- jquery - 在 laravel 5.4 中使用 jQuery ajax 的动态依赖下拉列表
- java - 如何比较java中泛型方法中的数组?
- java - 智能代理如何与数据库一起工作?
- c# - .NET 中的强名称程序集是否确保代码没有被篡改?
- c# - NullReferenceException 说,无法在我的一个实体框架对象中设置日期时间