Skip to content

Instantly share code, notes, and snippets.

@LowriWilliams
Created May 20, 2020 09:57
Show Gist options
  • Save LowriWilliams/d212f9f4d11a904dda17812a1d3d0ef2 to your computer and use it in GitHub Desktop.
Save LowriWilliams/d212f9f4d11a904dda17812a1d3d0ef2 to your computer and use it in GitHub Desktop.
corona/change_data_type
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 770 entries, 0 to 769\n",
"Data columns (total 8 columns):\n",
"Sno 770 non-null int64\n",
"Date 770 non-null object\n",
"Province/State 585 non-null object\n",
"Country 770 non-null object\n",
"Last Update 770 non-null object\n",
"Confirmed 770 non-null int64\n",
"Deaths 770 non-null int64\n",
"Recovered 770 non-null int64\n",
"dtypes: int64(4), object(4)\n",
"memory usage: 48.2+ KB\n"
]
}
],
"source": [
"# Change the data type of the Confirmed, Deaths and Recovered columns to integers\n",
"\n",
"df['Confirmed'] = df['Confirmed'].astype(int)\n",
"df['Deaths'] = df['Deaths'].astype(int)\n",
"df['Recovered'] = df['Recovered'].astype(int)\n",
"\n",
"# Check if it was successful\n",
"\n",
"df.info()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment