python - Issue with reading partial header CSV using pandas.read_csv -


i'm trying read csv file using pandas.read_csv when files header not full, i.e., columns have names, others empty.
when reading data frame using .iloc columns header not have names. reason columns not have names column size variable , did not assign name each column.

here's example of code, input file , output

dataframe = pandas.read_csv('filename.csv',\                             sep = ",",\                             header = 0) dataframe = dataframe.iloc[::] dataset = dataframe.values[:,0:] 

input file:

a b c            3 5 0      1    2   3  3   5   4      5    6   7  3   5   8      9    10  11  3   5   12     13   14  15 

dataset output:

dataset = [[1,2,3][5,6,7][9,10,11][13,14,15]] 

how can dataframe use entire array (without header)?

i think need .values numpy ndarray.

from io import stringio  csv_file = stringio("""a b c 3 5 0 1 2 3 3 5 4 5 6 7 3 5 8 9 10 11 3 5 12 13 14 15""")  df = pd.read_csv(csv_file,sep='\s',engine='python') df.values 

output:

array([[ 1,  2,  3],        [ 5,  6,  7],        [ 9, 10, 11],        [13, 14, 15]]) 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -