0% found this document useful (0 votes)
5 views3 pages

Test - 1

The document contains a series of code cells demonstrating the use of the pandas library in Python for data manipulation. It includes creating DataFrames from lists, dictionaries, and Series, as well as handling missing values and customizing DataFrame indices. The code snippets illustrate various functionalities of pandas, such as displaying data and modifying structures.

Uploaded by

saer3935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Test - 1

The document contains a series of code cells demonstrating the use of the pandas library in Python for data manipulation. It includes creating DataFrames from lists, dictionaries, and Series, as well as handling missing values and customizing DataFrame indices. The code snippets illustrate various functionalities of pandas, such as displaying data and modifying structures.

Uploaded by

saer3935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "c566da12-b911-410a-96db-b138d2b9faba", "metadata": { "tags": [] }, "outputs": [], "source": [ "import pandas as pd" ]

}, { "cell_type": "code", "execution_count": 6, "id": "9cd4e75f-3f27-4cde-ba22-f5f5c042a1d2", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream",
"text": [ "Empty DataFrame\n", "Columns: []\n", "Index: []\n" ] } ], "source": [ "df = pd.DataFrame()\n", "print(df)" ] }, { "cell_type": "code", "execution_count": 14, "id": "7360f1ba-
21df-4309-b98b-d914f37de61e", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
03
14
25
\n", "
" ], "text/plain": [ " 0\n", "0 3\n", "1 4\n", "2 5" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ser = pd.Series([3,4, 5])\n", "df =
pd.DataFrame(data=ser)\n", "df" ] }, { "cell_type": "code", "execution_count": 18, "id": "900e443e-f994-476c-b7bf-c2ecc02c319e", "metadata": { "tags": [] }, "outputs": [ { "data": {
"text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
01
12
23
34
45
\n", "
" ], "text/plain": [ " 0\n", "0 1\n", "1 2\n", "2 3\n", "3 4\n", "4 5" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#create a DataFrame from
list=arry\n", "f =[1,2,3,4,5]\n", "df= pd.DataFrame(f)\n", "df" ] }, { "cell_type": "code", "execution_count": 4, "id": "ae438e57-0d11-46b3-9715-a9c187204e5b", "metadata": { "tags":
[] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Name Age
0a 20
1b 30
2e 50
\n", "
" ], "text/plain": [ " Name Age\n", "0 a 20\n", "1 b 30\n", "2 e 50" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "data =[['a', 20],['b
',30],['e',50] ]\n", "#df = pd.DataFrame(data,columns=['Name', 'Age'])\n", "#df = pd.DataFrame(data,columns=['Name', 'Age'])\n", "#df\n", "# when i want to chang outpout the
number float ,intger ,double \n", "df =pd.DataFrame(data,columns=['Name', 'Age'] )\n", "df\n" ] }, { "cell_type": "code", "execution_count": 42, "id": "e82601e1-5d50-43db-8679-
e3eead8e4820", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Name Age
0 tom 25
1 jeck 33
2 steve 55
3 Ricky 32
\n", "
" ], "text/plain": [ " Name Age\n", "0 tom 25\n", "1 jeck 33\n", "2 steve 55\n", "3 Ricky 32" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [
"#Dictionaries\n", "data ={'Name':['tom', 'jeck', 'steve', 'Ricky'], 'Age':[25,33,55,32]}\n", "df = pd.DataFrame(data)\n", "df" ] }, { "cell_type": "code", "execution_count": 43, "id":
"6182f5b3-9e99-46ef-b70a-3d88740163b4", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Name Age
rank1 tom 25
rank2 jeck 33
rank3 steve 55
rank4 Ricky 32
\n", "
" ], "text/plain": [ " Name Age\n", "rank1 tom 25\n", "rank2 jeck 33\n", "rank3 steve 55\n", "rank4 Ricky 32" ] }, "execution_count": 43, "metadata": {}, "output_type":
"execute_result" } ], "source": [ "#how to change the index 0,1,2,3 that set\n", "data ={'Name':['tom', 'jeck', 'steve', 'Ricky'], 'Age':[25,33,55,32]}\n", "df = pd.DataFrame(data,
index=['rank1', 'rank2', 'rank3', 'rank4',])\n", "df\n" ] }, { "cell_type": "code", "execution_count": 13, "id": "d5c2a475-ac12-46dd-a641-38ab11e591db", "metadata": { "tags": [] },
"outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Name Age
0 tom 25
1 jeck 33
2 steve 55
3 Ricky 32
\n", "
" ], "text/plain": [ " Name Age\n", "0 tom 25\n", "1 jeck 33\n", "2 steve 55\n", "3 Ricky 32" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [
"#dict columns \n", "import pandas as pd\n", "data ={'Name':['tom', 'jeck', 'steve', 'Ricky'], 'Age':[25,33,55,32]}\n", "df = pd.DataFrame.from_dict(data, orient='columns')\n", "df" ]
}, { "cell_type": "code", "execution_count": 106, "id": "62af75a6-5a02-4df9-a31e-18cc606a469a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
a b c f
Name tom jeck steve Ricky
Age 25 33 55 32
\n", "
" ], "text/plain": [ " a b c f\n", "Name tom jeck steve Ricky\n", "Age 25 33 55 32" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#name
the index the the value \n", "data ={'Name':['tom', 'jeck', 'steve', 'Ricky'], 'Age':[25,33,55,32]}\n", "df = pd.DataFrame.from_dict(data, orient='index',columns=['a','b','c','f'])\n", "df" ]
}, { "cell_type": "code", "execution_count": 98, "id": "7822175c-5cbd-4a7e-8568-a0c6c67f0f77", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
a b c d
Name tom jeck steve Ricky
Age 25 33 55 32
\n", "
" ], "text/plain": [ " a b c d\n", "Name tom jeck steve Ricky\n", "Age 25 33 55 32" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#ues
Used together \n", "data ={'Name':['tom', 'jeck', 'steve', 'Ricky'], 'Age':[25,33,55,32]}\n", "df = pd.DataFrame.from_dict(data, orient='index', columns=['a','b','c','d',])\n", "df" ] }, {
"cell_type": "code", "execution_count": 14, "id": "e2f08f58-7ebe-40c2-a01d-a2627c5d8ef8", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream",
"text": [ "0 NaN\n", "1 NaN\n", "Name: Name, dtype: float64\n" ] } ], "source": [ "import pandas as pd\n", "\n", "data =[{'a': 2 , 'b': 33 , }, {'a': 22 ,'b':33 , 'c':33}]\n", "df =
pd.DataFrame(data,columns=['Name', 'Age'])\n", "#we can also identyfil the columns using [dc]\n", "#print(dc[1])\n", "print(df['Name']د\n", " " ] }, { "cell_type": "code",
"execution_count": 19, "id": "775e6cd4-c634-4bdb-b5cf-5ff763202a3f", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ab c
0 1 2 NaN
1 5 5 20.0
\n", "
" ], "text/plain": [ " a b c\n", "0 1 2 NaN\n", "1 5 5 20.0" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# when dict dont have value you
can see the \"c\"\n", "import pandas as pd \n", "data = [{'a':1, 'b':2},{'a':5, 'b':5, 'c':20}]\n", "df=pd.DataFrame(data)\n", "df " ] }, { "cell_type": "code", "execution_count": 20, "id":
"47b18ecd-52ad-42bd-b617-e724c797d78b", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ab c
first 1 2 NaN
decond 5 5 20.0
\n", "
" ], "text/plain": [ " a b c\n", "first 1 2 NaN\n", "decond 5 5 20.0" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd \n",
"data = [{'a':1, 'b':2},{'a':5, 'b':5, 'c':20}]\n", "df=pd.DataFrame(data, index=['first', 'decond'])\n", "df " ] }, { "cell_type": "code", "execution_count": 27, "id": "bedba0e3-029e-4e81-
b5bf-a9a1669eeda8", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0 1\n", "0 Alex 10\n", "1 bod 12\n", "2 clarke 13\n", "-------------\n",
"0 Alex\n", "1 bod\n", "2 clarke\n", "Name: 0, dtype: object\n" ] } ], "source": [ "#column Selection\n", "import pandas as pd \n", "data = [['Alex',10],['bod',12],['clarke',13]]\n", "df =
pd.DataFrame(data)\n", "print(df)\n", "print(\"-------------\")\n", "print (df[0])" ] }, { "cell_type": "code", "execution_count": 30, "id": "bd899795-8b40-43e6-8978-ba728d144911",
"metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " name age\n", "0 Alex 10\n", "1 bod 12\n", "2 clarke 13\n", "-------------\n", "0 10\n", "1
12\n", "2 13\n", "Name: age, dtype: int64\n" ] } ], "source": [ "#column Selection\n", "import pandas as pd \n", "data = [['Alex',10],['bod',12],['clarke',13]]\n", "df =
pd.DataFrame(data,columns=['name','age'])\n", "print(df)\n", "print(\"-------------\")\n", "print (df['age'])" ] }, { "cell_type": "code", "execution_count": 31, "id": "b48233c2-7310-4ce2-
aa52-c445c46abdfc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
name age address
0 Alex 10 aaa
1 bod 12 gfg
2 clarke 13 dde
\n", "
" ], "text/plain": [ " name age address\n", "0 Alex 10 aaa\n", "1 bod 12 gfg\n", "2 clarke 13 dde" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ],
"source": [ "#columns Addition\n", "df['address']=['aaa','gfg','dde']\n", "df\n" ] }, { "cell_type": "code", "execution_count": 32, "id": "59601cc5-dfa2-417a-b936-7074241c2f9f",
"metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deleting the fires colum using del \n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
name address
0 Alex aaa
1 bod gfg
2 clarke dde
\n", "
" ], "text/plain": [ " name address\n", "0 Alex aaa\n", "1 bod gfg\n", "2 clarke dde" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#pop=
whem i wnat deleting ues the pop \n", "print(\"deleting the fires colum using del \")\n", "df.pop('age')\n", "df" ] }, { "cell_type": "code", "execution_count": 35, "id": "7c6dcea1-8f95-
4749-91c9-f35ba0c93256", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
one tow
a 1.0 1
b 2.0 2
c 3.0 3
d NaN 4
\n", "
" ], "text/plain": [ " one tow\n", "a 1.0 1\n", "b 2.0 2\n", "c 3.0 3\n", "d NaN 4" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Selection
by label \n", "#Rows can be selected by passing row label to a loc function\n", "d = {'one': pd.Series([1,2,3,], index=['a', 'b', 'c']),\n", " 'tow': pd.Series([1,2,3,4], index= ['a', 'b' ,'c',
'd'])}\n", "df = pd.DataFrame(d)\n", "df" ] }, { "cell_type": "code", "execution_count": 37, "id": "11b18918-d561-4628-99aa-eb3715f7bb60", "metadata": { "tags": [] }, "outputs": [ {
"data": { "text/plain": [ "one 1.0\n", "tow 1.0\n", "Name: a, dtype: float64" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Selection by
label \n", "#Rows can be selected by passing row label to a loc function\n", "d = {'one': pd.Series([1,2,3,], index=['a', 'b', 'c']),\n", " 'tow': pd.Series([1,2,3,4], index= ['a', 'b' ,'c',
'd'])}\n", "df = pd.DataFrame(d)\n", "#df\n", "df.loc['a']" ] }, { "cell_type": "code", "execution_count": 4, "id": "295b96fd-33d4-4879-b7a0-21e57d1d14ed", "metadata": { "tags": [] },
"outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ab
012
134
056
178
\n", "
" ], "text/plain": [ " a b\n", "0 1 2\n", "1 3 4\n", "0 5 6\n", "1 7 8" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Additiom of rows \n",
"import pandas as pd\n", "df = pd.DataFrame ([[1,2],[3,4]], columns =['a','b'])\n", "df2= pd.DataFrame ([[5,6], [7,8]], columns =['a','b'])\n", "\n", "df = df._append(df2)\n", "df " ] }, {
"cell_type": "code", "execution_count": 41, "id": "94211b94-1fee-44aa-8014-e3c856d20870", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
A B C D E F
0 1.0 2013-01-02 1.0 3 test foo
1 1.0 2013-01-02 1.0 3 train foo
2 1.0 2013-01-02 1.0 3 test foo
3 1.0 2013-01-02 1.0 3 train foo
\n", "
" ], "text/plain": [ " A B C D E F\n", "0 1.0 2013-01-02 1.0 3 test foo\n", "1 1.0 2013-01-02 1.0 3 train foo\n", "2 1.0 2013-01-02 1.0 3 test foo\n", "3 1.0 2013-01-02 1.0 3 train foo" ]
}, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 = pd.DataFrame(\n", " {\n", " \"A\": 1.0,\n", " \"B\": pd.Timestamp(\"20130102\"),\n", "
\"C\": pd.Series(1, index=list(range(4)), dtype=\"float32\"),\n", " \"D\": np.array([3] * 4, dtype=\"int32\"),\n", " \"E\": pd.Categorical([\"test\", \"train\", \"test\", \"train\"]),\n", " \"F\":
\"foo\",\n", " }\n", " )\n", "df2" ] }, { "cell_type": "code", "execution_count": 39, "id": "8156ef63-3fa5-4248-bc11-272e2e09391d", "metadata": { "tags": [] }, "outputs": [ { "data": {
"text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
A B C D
2013-01-01 -0.758646 -0.831293 0.213619 -1.012936
2013-01-02 0.858895 -0.115271 1.743286 -0.897626
2013-01-03 0.848148 1.458501 -1.321339 0.807906
2013-01-04 -0.687208 1.274620 -0.273903 1.923105
A B C D
2013-01-05 -1.304873 -1.154423 0.531805 -0.959242

2013-01-06 1.528364 -2.168569 -0.063874 1.460076


\n", "
" ], "text/plain": [ " A B C D\n", "2013-01-01 -0.758646 -0.831293 0.213619 -1.012936\n", "2013-01-02 0.858895 -0.115271 1.743286 -0.897626\n", "2013-01-03 0.848148
1.458501 -1.321339 0.807906\n", "2013-01-04 -0.687208 1.274620 -0.273903 1.923105\n", "2013-01-05 -1.304873 -1.154423 0.531805 -0.959242\n", "2013-01-06 1.528364
-2.168569 -0.063874 1.460076" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dates = pd.date_range(\"20130101\", periods=6)\n",
"dates\n", "df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list(\"ABCD\"))\n", "df" ] }, { "cell_type": "code", "execution_count": 37, "id": "0df83069-8d21-42e5-
ac9a-859c3bd6ea47", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "0 1.0\n", "1 3.0\n", "2 5.0\n", "3 NaN\n", "dtype: float64" ] }, "execution_count": 37,
"metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pandas as pd \n", "s = pd.Series([1, 3, 5, np.nan])\n", "s" ] }, { "cell_type": "code",
"execution_count": 75, "id": "8233d593-1eba-4415-8b19-f676a48f7b0a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "( movieId title \\\n", " 0 1 Toy Story (1995)
\n", " 1 2 Jumanji (1995) \n", " 2 3 Grumpier Old Men (1995) \n", " 3 4 Waiting to Exhale (1995) \n", " 4 5 Father of the Bride Part II (1995) \n", " ... ... ... \n", " 9737 193581 Black
Butler: Book of the Atlantic (2017) \n", " 9738 193583 No Game No Life: Zero (2017) \n", " 9739 193585 Flint (2017) \n", " 9740 193587 Bungo Stray Dogs: Dead Apple (2018)
\n", " 9741 193609 Andrew Dice Clay: Dice Rules (1991) \n", " \n", " genres \n", " 0 Adventure|Animation|Children|Comedy|Fantasy \n", " 1 Adventure|Children|Fantasy \n", " 2
Comedy|Romance \n", " 3 Comedy|Drama|Romance \n", " 4 Comedy \n", " ... ... \n", " 9737 Action|Animation|Comedy|Fantasy \n", " 9738 Animation|Comedy|Fantasy \n", " 9739
Drama \n", " 9740 Action|Animation \n", " 9741 Comedy \n", " \n", " [9742 rows x 3 columns],\n", " movieId imdbId tmdbId\n", " 0 1 114709 862.0\n", " 1 2 113497 8844.0\n", " 2 3
113228 15602.0\n", " 3 4 114885 31357.0\n", " 4 5 113041 11862.0\n", " ... ... ... ...\n", " 9737 193581 5476944 432131.0\n", " 9738 193583 5914996 445030.0\n", " 9739
193585 6397426 479308.0\n", " 9740 193587 8391976 483455.0\n", " 9741 193609 101726 37891.0\n", " \n", " [9742 rows x 3 columns],\n", " userId movieId rating
timestamp\n", " 0 1 1 4.0 964982703\n", " 1 1 3 4.0 964981247\n", " 2 1 6 4.0 964982224\n", " 3 1 47 5.0 964983815\n", " 4 1 50 5.0 964982931\n", " ... ... ... ... ...\n", " 100831
610 166534 4.0 1493848402\n", " 100832 610 168248 5.0 1493850091\n", " 100833 610 168250 5.0 1494273047\n", " 100834 610 168252 5.0 1493846352\n", " 100835 610
170875 3.0 1493846415\n", " \n", " [100836 rows x 4 columns])" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd
\n", "da
=pd.read_csv('C:\\\\Users\\\\yy\\\\Downloads\\\\movies.csv'),pd.read_csv('C:\\\\Users\\\\yy\\\\Downloads\\\\links.csv'),pd.read_csv('C:\\\\Users\\\\yy\\\\Downloads\\\\ratings.csv'),\n",
"pd.read_csv('C:\\\\Users\\\\yy\\\\Downloads\\\\tags.csv'),\n", "da\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 68, "id": "bdc31ee8-0594-4a1b-ba19-c8ab19453349",
"metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n",
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
player Game1 Game2 Game3 Game4
0A 18 2 11 7
1B 22 3 8 65
2C 33 4 6 4
3D 19 5 5 3
4E 14 6 4 2
5F 14 7 3 3
6G 11 8 5 4
7H 20 7 6 5
\n", "
" ], "text/plain": [ " player Game1 Game2 Game3 Game4\n", "0 A 18 2 11 7\n", "1 B 22 3 8 65\n", "2 C 33 4 6 4\n", "3 D 19 5 5 3\n", "4 E 14 6 4 2\n", "5 F 14 7 3 3\n", "6 G 11 8 5
4\n", "7 H 20 7 6 5" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#create Dataframe \n", "df= pd.DataFrame({'player':
['A','B','C','D','E','F','G','H'],\n", " 'Game1':[18,22,33,19,14,14,11,20],\n", " 'Game2':[2,3,4,5,6,7,8,7],\n", " 'Game3':[11,8,6,5,4,3,5,6],\n", " 'Game4':[7,65,4,3,2,3,4,5]})\n", "df \n",
"#view DataFrame \n" ] }, { "cell_type": "code", "execution_count": null, "id": "eb77f41e-71f9-499d-8bfb-cde92a747451", "metadata": {}, "outputs": [], "source": [] }, { "cell_type":
"code", "execution_count": null, "id": "fdaa9cf1-3d51-4389-aa1d-4cd6e660ed87", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name":
"Python 3 (ipykernel)", "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.11.5" } }, "nbformat": 4, "nbformat_minor": 5 }

You might also like