When I'm reading a csv file using the pandas library, but when I print the head of the dataframe it doesn't show it as a dataframe but more like a list.
This is the code I tipped:
import pandas as pd
df = pd.read_csv('Path/File')
print(df.head())
The output looks like this
How do I get it show the data frame properly?
Related
I made an excel sheet using pandas dataframe to generate texts with clickable urls using the following code
import pandas as pd
df = pd.DataFrame({'link':['=HYPERLINK("https://ar.wikipedia.org/wiki/","wikipidia")',
'=HYPERLINK("https://www.google.com", "google")']})
df.to_excel('links.xlsx')
But currently i need to read the generated excel sheet (links.xlsx) using pandas.read_excel so i tried the following code:
import pandas as pd
excelDf=pd.read_excel('links.xlsx')
print(excelDf)
but this generates a dataframe with all zeroes in the link column.
Is there another way I can read the excel file i created, or another way to create an excel sheet containing clickable links on text using pandas dataframe that is readable?
you can do the same as a csv which is cleaner (avoids excel issues).
# %% write the date
import pandas as pd
df = pd.DataFrame({'link':['=HYPERLINK("https://ar.wikipedia.org/wiki/","wikipidia")',
'=HYPERLINK("https://www.google.com", "google")']})
df.to_csv('F:\\links.xlsx')
# %% read the data
import pandas as pd
excelDf=pd.read_csv('F:\\links.xlsx')
print(excelDf)
result:
Unnamed: 0 link
0 0 =HYPERLINK("https://ar.wikipedia.org/wiki/","w...
1 1 =HYPERLINK("https://www.google.com", "google")
When I tried to read data from a csv file, I got the result that is in a weird format.
import pandas as pd
df = pd.read_csv('HDMA Boston Housing Data.csv')
df
The file seems to be .txt file, but renamed and read like a .csv file.
I'm using jupyter nootbook and I want to display my data frame.
I have this code:
import pandas as pd
import openpyxl
f = pd.ExcelFile('urbanpop.xlsx')
f.sheet_names
df1 = f.parse("1960-1966")
print(df1)
When I print the data frame (df1), I get something like that:
And what I want to get, is something like that:
How can I do it?
Thank you.
I found a solution.
Just need to write "df1" instead of "print(df1)"
I've created a CSV file from a dataframe with a shape of (1081, 165233). I did this using this command: df2.to_csv("better_matched.csv")
However, whenever I try to load this csv as a pandas dataframe later on, the shape of the dataframe becomes (660, 165234). This is the code that I'm using to load the csv:
import pandas as pd
df = pd.read_csv("/content/drive/My Drive/Authorship/better_matched.csv")
df.shape
I think I need to change some parameters with .to_csv() or .read_csv() functions. What can be done?
print(pd.read_excel(File,Sheet_Name,0,None,0,None,["Column_Name"],1))
Since i am a noob to pandas i want to retrive a column of ExcelSheet using pandas in the form of array. I tried the code above but it didn't really work.
The way to do it is:
import pandas as pd
df = pd.read_excel(File,sheetname=Sheet_Name)
print(df['column_name'])