Trying to answer this question Get List of Unique String per Column we ran into a different problem from my dataset. When I import this CSV file to the dataframe every column is OBJECT type, we need to convert the columns that are just number to real (number) dtype and those that are not number to String dtype.
Is there a way to achieve this?
I have tried following code from following article Pandas: change data type of columns but did not work.
df = pd.DataFrame(a, columns=['col1','col2','col3'])
As always thanks for your help
pd.to_numeric in an
cvrtd = pd.to_numeric(df.values.ravel(), errors='coerce').reshape(-1, len(df.columns)) pd.DataFrame(np.where(np.isnan(cvrtd), df.values, cvrtd), df.index, df.columns)<hr>
<strong>Note</strong> These are not exactly the same. For some column that contains mixed values, option 2 converts what it can while option 2 leaves everything in that column an object. Looking at your file, I'd choose option 1.<hr>
df = pd.read_csv('HistorianDataSample/HistorianDataSample.csv', skiprows=[1, 2])