简体   繁体   English

Python Pandas从一列中读取csv,然后将各列分开

[英]Python pandas read a csv from one column then seperate columns

I have a csv that needs seperation based on number of issues, and im currently getting an error with my code 我有一个需要根据问题数量进行分隔的csv,目前我的代码出现错误

 dfcleancsv = pd.read_csv('InitialQuerydataOpen.csv', sep=",")


ValueError: Expected 1 fields in line 1609, saw 55

What I have 我有的

Column1 Column2
1583    FIT-491
1584    FIT-4276,"TC 1140.0024, 1140.0025, 1140.0026, 1140.0179, 1140.018"

What I want 我想要的是

Column1 Column 2    Column3   Column4  Column5    Column6  Column7
1583    FIT-491
1584    FIT-4276  1140.0024 1140.0025 1140.0026 1140.0179 1140.018

Here you go: 干得好:

with open('test.txt') as f:
        data = {i:txt.strip().split(',') for i,txt in enumerate(f.readlines())}

df = pd.DataFrame.from_dict(data, orient='index')
print(df)

## -- End pasted text --
      0          1          2          3          4          5         6
0  1583  FIT-491         None       None       None       None      None
1  1584   FIT-4276  1140.0024  1140.0025  1140.0026  1140.0179  1140.018

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

相关问题 熊猫read_CSV读入一列,不会以“,”分开 - Pandas read_CSV reading into one column, won't seperate on “,” Pandas:将日期和时间列作为一个日期时间列的 read_csv - Pandas: read_csv with date and time columns as one datetime column 如果列没有标题,如何使用 python 分隔一列 CSV 文件,然后将其保存到新的 excel 文件中? - How to use python to seperate a one column CSV file if the columns have no headings, then save this into a new excel file? Python Pandas.to_csv 无法将分号(;)的列导出为一列 - Python Pandas.to_csv unable to export columns with semicolon(;) as one column python pandas.read_csv 库在一列中打印所有内容 - python pandas.read_csv library print everything in one column Python Pandas-read_csv数据框正在从列中删除值 - Python pandas - read_csv Dataframe is dropping values from columns 在 pandas read_csv 文件中打开 .csv 文件时,显示一列中的所有列 - When opening .csv file in pandas read_csv file, shows all the columns in one column 从 .xlsx 中的列中读取数据并使用 python 将每个数据保存为单独的 .txt 文件 - Read data from columns in .xlsx and save each one as seperate .txt file with python 从python中的csv读取列 - Read columns from csv in python 按 pandas python 中的列号读取 csv 文件 - Read csv file by column number in pandas python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM