I'm trying to save a pandas DataFrame in binary data formats and book says that pandas objects all have save method which writes the data to disc as a pickle. but when I run the code there is an error. Is there save method for pandas objects in pandas new versions? I'm using pandas 0.25.3
import pandas as pd
frame = pd.read_csv('PandasTest.csv')
frame.save('PandasTest_Pickle')
The error is:
AttributeError: 'DataFrame' object has no attribute 'save'
As others in comment section suggested, use 'to_pickle' and 'read_pickle' methods. For e.g,
import pandas as pd
frame=pd.read_csv('data.csv')
frame.to_pickle('frame_pickle')
pd.read_pickle('frame_pickle')
Related
I'm using a Jupyter notebook and I'm trying to open a data file and keep getting an error code AttributeError:'pandas._libs.properties.AxisProperty' object has no attribute 'unique'. This is my first time using Jupyter So I am not familiar with any error like this.
import pandas as pd
df = pd.DataFrame
df - pd.read_csv("C:/Users/yusra/OneDrive/Documents/vgsales.csv")
df
You are not using pd.DataFrame right. See below corrected code:
import pandas as pd
df=pd.read_csv("C:/Users/yusra/OneDrive/Documents/vgsales.csv")
df
I've just started a python for finance course and am brand new to programming. I'm trying to import a csv file into "fb" dataframe but it keeps giving me the following error: type object 'DataFrame' has no attribute 'read_csv'.
Here is my code:
import pandas
import pandas as pd
fb=pd.DataFrame.read_csv('data/facebook.csv')
Instead of
fb=pd.DataFrame.read_csv('data/facebook.csv')
Try
fb=pd.read_csv('data/facebook.csv')
I have a dataframe that I have generated myself like:
I would want to save it using pickle (the only way I know to do that) using:
df.to_pickle(file_name)
To use it then with:
df = pd.read_pickle(file_name)
The problem is that using this I'm getting a file that the other program don't know how to read:
df = pd.read_pickle("dataframe.pkl")
print(df)
I'm getting an AttributeError:
AttributeError: 'DataFrame' object has no attribute '_data'
Thanks for your help.
Previously i was using python DictReader to read and load each row in python dict, But now due to some design changes i have to use pandas to do the same. But while trying to achieve same behaviour i am using this code
for idx,row_r in enumerate(pd.read_csv(input_file_path,chunksize=10000, skiprows=skip_n_rows).to_dict()):
But i am getting this error
AttributeError: 'TextFileReader' object has no attribute 'to_dict'
python 3.7.6
pandas 0.23.0
P.S i am using chunksize because CSV file is large.
Hello I am trying to read and open two excel files into one data frame however I get this error.
AttributeError: 'dict' object has no attribute 'parse'
My objective is to use pandas and merge these two xlsx files into a data frame. How do I this. Help appreciated Here is my code below:
# import modules
from IPython.display import display
import pandas as pd
import numpy as np
pd.set_option("display.max_rows", 999)
pd.set_option('max_colwidth',100)
%matplotlib inline
# filenames
file_names = ["data/OrderReport.xlsx", "data/OrderReport2.xlsx"]
reading_files = [(pd.read_excel(f, sheetname=None, parse_cols=None))for f in file_names]
frames = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in reading_files]
With the "new" read_excel function it creates a dict of DataFrames (if you pass sheetname=None), there's no need to call parse (as there is no ExcelFile). Previously you had to create an ExcelFile and then parse each sheet. See here.
Therefore reading_files is a list of dicts of DataFrames... It's unclear how you want to merge this into a single-DataFrame (there's lots of choices!).