I have 2 pandas dataframes:
df1 is an empty dataframe: import pandas as pd import numpy as np
df1 = pd.DataFrame(columns=['Start','End','Duration'])
df1
Out[1]:
Empty DataFrame
Columns: [Start, End, Duration]
Index: []
df2 contains:
df2 = pd.DataFrame(np.array([None] * 3).reshape(-1,3),columns=['Start','End','Duration'])
df2['Start'] = 483
df2['End'] = 523
df2['Duration'] = 0.8
df2
Out[2]:
Start End Duration
0 483 523 0.8
df2['Start']
Out[3]:
0 483
Name: Start, dtype: int64
I want to concatenate the 2 dataframes:
df1= pd.concat([df1, df2], ignore_index=True)[df1.columns.tolist()]
df1 is:
df1
Out[4]:
Start End Duration
0 483.0 523.0 0.8
As you can see now "Start" and "End" are float... is there a way to keep them int?
You can use astype:
df1[['Start','End']] = df1[['Start','End']].astype(int)
output:
Start End Duration
0 483 523 0.8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With