0

I have a csv which has the 500 columns .I want to append the values of one column after the other.

The csv is as follows

A B  
0 3 
1 4 
2  

The output must be in the following format

A 
0
1
2
3
4

That means the large number of column values are to be appended in just one column .

arpita
  • 51
  • 5
  • what have you attempted so far? are you having a specific problem with the code you have written? can you post your code and detail the errors with it? – t_warsop Jul 23 '19 at 14:46
  • do you need to concat all columns from the csv to one, so something like [this](https://stackoverflow.com/questions/42786804/concatenate-all-columns-in-a-pandas-dataframe)? – FObersteiner Jul 24 '19 at 09:50

1 Answers1

0

You can do this way:-

#importing helping module(s)
import pandas as pd

#reading the csv data
df = pd.read_csv("path/to/csv")

#converting into numpy array
base = df.values.T

#converting to pandas series obj
base = pd.Series(base.ravel())

#filterning out nan values
base = base.dropna().values
print(base)
Vicrobot
  • 3,795
  • 1
  • 17
  • 31
  • i am getting an error TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''@Vicrobot – arpita Jul 24 '19 at 05:01
  • @arpita I've updated my answer, so that non-native dtypes would also be processed. – Vicrobot Jul 24 '19 at 09:24
  • @Vicrobot: why do you import `numpy`? – FObersteiner Jul 24 '19 at 09:39