Python中文
首页
教程
问答
标签
搜索
登录
注册
数据帧列分隔
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个很大的数据帧,其中只有一列包含所有值。我需要把数据分成更多的列。经过反复试验,我放弃了,寻求你的帮助。你知道吗</p> <p>数据帧的头部如下所示: 行是一个序列对象。不是价值观</p> <pre><code> column1 --------------------------------------------------------------------- MultiIndex1 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 | 1.00 2.00 3.00 4.00 5.00 6.00 7.00 </code></pre> <p>我期望的输出应该如下所示:</p> <pre><code> column1|column2|column3|column4|column5|column6|column7 --------------------------------------------------------------------- MultiIndex1 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00 | 7.00 </code></pre> <p>我试着: 测向列=['col1'、'col2'、'col3'、'col4'、'col5'…]</p> <p>我试着把它变成一个系列,然后再回到df。你知道吗</p> <p>我试过申请。结构拆分功能。你知道吗</p> <p>很多切片和浓缩,但没有成功。你知道吗</p> <p>我们将非常感谢您的帮助。 谢谢!你知道吗</p> <p>以下是我的数据集的前几行,作为示例:</p> <p>日期和AALR3是行多索引</p> <p>2019-01-02;AALR3;00000000 20;0000000000 13.300000;000000000000000 100;10:00:04.961;1;2019-01-02;000086597137782;000000000 310091;2;2019-01-02;000086597142909;000000000 310092;1;0;00000072;00000174 2019-01-02;AALR3;0000000010;000000000013.310000;0000000000000003000;10:00:04.961;1;2019-01-02;000086597135827;000000000310088;2;2019-01-02;000086597142909;000000000310089;1;0;00000120;00000174 2019-01-02;AALR3;0000000050;000000000013.390000;000000000000000200;10:11:40.214;1;2019-01-02;000086597182855;000000000400273;1;2019-01-02;000086597151579;000000000400274;2;0;000000058 2019-01-02;AALR3;0000000040;000000000013.380000;000000000000000100;10:11:40.214;1;2019-01-02;000086597182855;000000000400271;1;2019-01-02;000086597151578;000000000400272;2;0;00000058;00000174 2019-01-02;AALR3;0000000030;000000000013.380000;000000000000000100;10:11:40.214;1;2019-01-02;000086597182855;000000000400269;1;2019-01-02;000086597151189;000000000400270;2;0;00000058;00000308</p> <p>我读它的时候带着:</p> <pre><code> pd.read_csv('//path_to_file', sep=';') </code></pre> <p>我想这样命名列。你知道吗</p> <pre><code> df.columns = ['Session Date','Instrument Symbol','Trade Number','Trade Price','Traded Quantity', 'Trade Time','Trade Indicator','Buy Order Date','Sequential Buy Order Number', 'Secondary Order ID - Buy Order','Aggressor Buy Order Indicator','Sell Order Date', 'Sequential Sell Order Number','Secondary Order ID - Sell Order','Aggressor Sell Order Indicator', 'Cross Trade Indicator','Buy Member','Sell Member'] </code></pre> <p>更新:</p> <p>解决方案很有效,非常感谢。你知道吗</p> <p><a href="https://i.stack.imgur.com/JAcFM.png" rel="nofollow noreferrer">I is almost the way i want it. Is there a way to make the duplicate indexes a MultiIndex as well? I managed to make the dates, but not the symbol. Thanks</a></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你看到的是<code>MultiIndex Dataframe</code>,你要找的是<code>SingleIndex dataframe</code>, 试试看</p> <pre><code>df = df.reset_index() df.columns = ['col1','col2','col3','col4','col5','col6','col7'] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
10 回答
将Pandas数据帧转换为scipy稀疏矩阵
5 回答
将Pandas数据帧转换为Spark Datafram时出现问题
3 回答
将pandas数据帧转换为spark DataFram时出错
4 回答
将Pandas数据帧转换为spark datafram时收到错误
6 回答
将Pandas数据帧转换为Spark数据帧
7 回答
将Pandas数据帧转换为Tensorflow数据
8 回答
将Pandas数据帧转换为tkinter obj
8 回答
将pandas数据帧转换为XML
6 回答
将Pandas数据帧转换为值sql语句
9 回答
将pandas数据帧转换为元组
10 回答
将pandas数据帧转换为元组列表
1 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
8 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
3 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
9 回答
将pandas数据帧转换为内存中类似文件的对象?
3 回答
将Pandas数据帧转换为内存功能(&F)
3 回答
将pandas数据帧转换为列表列表
3 回答
将pandas数据帧转换为列表列表以输入到RNN
3 回答
将Pandas数据帧转换为单行DataFram
1 回答