0

I have a dataset where I must read in the data as a 2d array using

import csv

with open('#Name.csv', newline ='') as csvfile:
     arrayFull = list(csv.reader(csvfile))

which creates a 2d array. I then use

for i in range(2):
    arrayFull.pop(0)

to remove the first two rows of the 2d array (my dataset only requires data from the 3rd row and below). I then assign the 2d array to a Pandas Dataframe using

import pandas as pd
dataframe_1 = pd.DataFrame(arrayFull)

Now I am trying to split "dataframe_1" into 2 dataframes by column. I have 8 columns and I want 2 dataframes with 4 columns each. The issue arises due to the column names being A_first, A_second, A_third, A_fourth, A_first, A_second, A_third, A_fourth.

I cannot use the pandas dataframe copy() function because there are duplicate column names. mangle_dupe_colsalso does not work from what I understand because that requires the csv to be read dataframe from the beginning, but I created a dataframe by setting a 2d array. Any ideas on what to do?

Nimitz
  • 3
  • 4

1 Answers1

0

You can use df.iloc to use numeric index.

df_first_four_cols = dataframe_1.iloc[:,0:4]
df_second_four_cols = dataframe_1.iloc[:,4:]

fusion
  • 1,327
  • 6
  • 12