Home > other >  How python will not row, column name non numeric TXT files into dataframe format
How python will not row, column name non numeric TXT files into dataframe format

Time:09-26

Readlines () to read directly after the dataframe, only is a column, ReadLine () read line by line, add is always an error, the great god give directions, thank you

CodePudding user response:

This is a standard CSV format file you
With read_csv method directly line

 
The import pandas as pd
My_data=https://bbs.csdn.net/topics/pd.read_csv (' D:/temp/yourfilename CSV, the header=None, names=[' col1, col2, col3, 'col4', 'col5', 'col6', 'col7', 'col8'], index_col=None)

CodePudding user response:

Thank you, settled, beginners, too obsessed with suffix. TXT the

CodePudding user response:

Could you tell me if there are a lot of columns, names themselves set up?

CodePudding user response:

reference sinat_39702436 reply: 3/f
could you please tell me if there are a lot of columns, names themselves set up?


A list that can construct first namelist, loop set column names, and then call the method that 1st floor, the namelist assignment to names,

CodePudding user response:

How many such as a line of a comma, must be know,
Assuming that there are 20 comma, means that the 21 elements, the circulation way available list comprehensions set

 
Count_range=20 + 1
Namelist=[' col + STR (I + 1) for I in range (0, count_range)]
Print (namelist)
  • Related