简体   繁体   English

将数据框列标题和值拆分为多个列

[英]split dataframe column header and values into multiple columns

I've uploaded my csv file on Azure, but for some reason it became like this 我已经在Azure上上传了csv文件,但是由于某种原因,它变成了这样

 nominal;data;curs;cdx         Column 1
0          1;21.06.2000;28  2300;������ ���
1          1;22.06.2000;28  2200;������ ���
2          1;23.06.2000;28  1900;������ ���
3          1;24.06.2000;28  1700;������ ���
4          1;27.06.2000;28  1300;������ ���
5          1;28.06.2000;28  1100;������ ���

Basically instead of four columns nominal , data , curs , cdx I got two columns with one having all the values and the last one (it is empty or something because the last column has encoding issue) - no idea what. 基本上没有四列nominaldatacurscdx而是有两列,其中一列具有所有值,最后一列(它是空的或因为上一列有编码问题,所以它是空的)-不知道是什么。

I have deleted the column Column 1 like this 我已经删除了列Column 1这样的列

import pandas as pd

def azureml_main(dataframe1 = None, dataframe2 = None):
    dataframe1.drop(['Column 1'], axis = 1, inplace = True)
    print('Input pandas.DataFrame #1:\r\n\r\n{0}'.format(dataframe1))
    return dataframe1,

How to split the first column into multiple now? 现在如何将第一列拆分为多个? To get 4 separate columns 获得4个单独的列

I am using pandas 0.18 我正在使用熊猫0.18

You need to split the column with: 您需要使用以下方法拆分列:

dataframe1['nominal;data;curs;cdx'].str.split(';',expand=True)

Then change the headers with: 然后使用以下命令更改标题:

dataframe1.columns = 'nominal;data;curs;cdx'.split(';')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM