Reputation: 59
Starting from a Pandas Dataframe with it's setup:
B13-111DATA.TIJD object
dtype: object
B13-111DATA.TIJD
StartTime
2020-03-30 00:00:00 292
2020-03-30 00:00:01 292
2020-03-30 00:00:02 292
2020-03-30 00:00:03 292
2020-03-30 00:00:04 292
... ...
2020-04-07 23:59:55 333
2020-04-07 23:59:56 333
2020-04-07 23:59:57 333
2020-04-07 23:59:58 333
2020-04-07 23:59:59 333
[777600 rows x 1 columns]
This Pandas Dataframe I would like to transform to a structuce like below:
B13-111DATA.TIJD int64
dtype: object
or
B13-111DATA.TIJD float64
dtype: object
I tried to use following line:
df = df[B13-111DATA.TIJD].astype(float)
But it returns me a simple "float" and errors my code
print(output.columns.values)
with an error "AttributeError: 'Series' object has no attribute 'columns'". It looks my dataFrame turned into a series. Could that be the case?
Pretty sure it is something simple many people already encountered here. Any tip or help would be appreciated.
Upvotes: 1
Views: 103
Reputation: 862641
Problem is there is reaasign DataFrame variable df
to Series
(column of DataFrame):
df = df['B13-111DATA.TIJD'].astype(float)
For correct converting assign back column, so df
stay DataFrame
:
df['B13-111DATA.TIJD'] = df['B13-111DATA.TIJD'].astype(float)
print (df)
Upvotes: 2