0% found this document useful (0 votes)
2 views

Store.ipynb - Colab

The document outlines a series of operations performed using pandas in Python, including creating DataFrames, exporting them to Excel files, and reading from those files. It demonstrates how to concatenate DataFrames, sort values, and upload a file to Google Colab. Finally, it reads data from an uploaded Excel file and prints its contents.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Store.ipynb - Colab

The document outlines a series of operations performed using pandas in Python, including creating DataFrames, exporting them to Excel files, and reading from those files. It demonstrates how to concatenate DataFrames, sort values, and upload a file to Google Colab. Finally, it reads data from an uploaded Excel file and prints its contents.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2/14/25, 9:53 AM Store_149.

ipynb - Colab

import pandas as pd
df=pd.DataFrame([[11,21,31],[1,22,32],[315,32,33]],
index=['one','two','three'],columns=['a','b','c'])
print(df)

a b c
one 11 21 31
two 1 22 32
three 315 32 33

print("Taking the input from Dataframe and storing in the Excel file")
df.to_excel("/content/pandas to excel.xlsx", sheet_name='pandas to excel')
b=pd.read_excel("/content/pandas to excel.xlsx")
print(b)

Taking the input from Dataframe and storing in the Excel file
Unnamed: 0 a b c
0 one 11 21 31
1 two 1 22 32
2 three 315 32 33

d=pd.DataFrame([[110,210,310],[12,220,320],[310,320,330]],
index=['four','five','six'],columns=['a','b','c'])
d.to_excel("/content/pandas to excel2.xlsx",sheet_name='pandas to excel')
z=pd.read_excel("/content/pandas to excel2.xlsx")
print(z)

Unnamed: 0 a b c
0 four 110 210 310
1 five 12 220 320
2 six 310 320 330

x=pd.read_excel("/content/pandas to excel.xlsx")
y=pd.read_excel("/content/pandas to excel.xlsx")
z=pd.concat([x, y], ignore_index=True) # Use pd.concat instead of append
z.to_excel('/content/pandas to excel3.xlsx', index=False) #Avoid saving the index
b=pd.read_excel("/content/pandas to excel3.xlsx")
print(b)

Unnamed: 0 a b c
0 one 11 21 31
1 two 1 22 32
2 three 315 32 33
3 one 11 21 31
4 two 1 22 32
5 three 315 32 33

df=z.sort_values(["a"])
print(df)
df.to_excel("/content/pandas to excel4.xlsx")

Unnamed: 0 a b c
1 two 1 22 32

https://colab.research.google.com/drive/11KmNNXLHtxLnRPQQIwGDjM7_c8lI1cLd#scrollTo=bh1aL1BcBB_n&printMode=true 1/3
2/14/25, 9:53 AM Store_149.ipynb - Colab
4 two 1 22 32
0 one 11 21 31
3 one 11 21 31
2 three 315 32 33
5 three 315 32 33
Unnamed: 0.1 Unnamed: 0 a b c
0 1 two 1 22 32
1 4 two 1 22 32
2 0 one 11 21 31
3 3 one 11 21 31
4 2 three 315 32 33
5 5 three 315 32 33

_from google.colab import files


uploaded=files.upload()
print(uploaded)

Choose Files test.xlsx


test.xlsx(application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) - 9691 bytes, last
modified: 2/14/2025 - 100% done
Saving test.xlsx to test.xlsx
{'test.xlsx': b'PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00\x9e,lok\x01\x00\x00\x1

df=pd.read_excel('/content/test.xlsx')
print(df)
print(list(df))
print(format(len(df)))

Unnamed: 0 Roll No Name Maths Science Social total


0 1 129 Diya 100 90 40 230
1 2 130 Riya 80 50 60 190
2 3 131 Sita 70 40 30 140
3 4 132 Sonu 45 60 90 195
4 5 133 Monu 55 100 60 215
5 6 134 Rohan 60 80 70 210
6 7 135 Soni 70 60 50 180
7 8 136 Rani 40 65 70 175
8 9 137 Tamil 85 70 60 215
9 10 138 yadav 70 75 70 215
['Unnamed: 0', 'Roll No', 'Name', 'Maths', 'Science', 'Social', 'total']
10

https://colab.research.google.com/drive/11KmNNXLHtxLnRPQQIwGDjM7_c8lI1cLd#scrollTo=bh1aL1BcBB_n&printMode=true 2/3
2/14/25, 9:53 AM Store_149.ipynb - Colab

https://colab.research.google.com/drive/11KmNNXLHtxLnRPQQIwGDjM7_c8lI1cLd#scrollTo=bh1aL1BcBB_n&printMode=true 3/3

You might also like