user13380066
user13380066

Reputation:

Pandas 'DataFrame' object has no attribute 'write' when trying to save it locally in Parquet file

Could you help me solve this error please?

I am trying to execute the following code to save a DataFrame locally as a partitiened Parquet file:

dfcitas.write.format("parquet")\
    .mode("overwrite")\
    .partitionBy("NPatente")\
    .save("/datos/dfcitas-particionado.parquet")

And this error is appearing:

AttributeErrorTraceback (most recent call last)
<ipython-input-164-9b06b4833bf9> in <module>()
----> 1 dfcitas.write.format("parquet")    .mode("overwrite")    .partitionBy("NPatente")    .save("/datos/dfcitas-particionado.parquet")
    
    /opt/conda/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
       3612             if name in self._info_axis:
       3613                 return self[name]
    -> 3614             return object.__getattribute__(self, name)
       3615 
       3616     def __setattr__(self, name, value):
    
    AttributeError: 'DataFrame' object has no attribute 'write'

The DataFrame that I am working on has the following 2 columns:

  1. NPatente
  2. ncitas

I am running the code on a dockerised Zeppelin and creating the dfcitas DataFrame using the following code:

# Importing the Pandas library
import pandas as pd

# Reading the cite75_99.txt.bz2 file in compressed format and sabing it to a DataFrame
df = pd.read_csv('/datos/cite75_99.txt.bz2', compression='bz2', header=0, sep=',', quotechar='"')

# Grouping the number of patents and counting the numbre of cites that each patent recieved in a new DataFrame
dfcitas = df.groupby('CITING')['CITED'].count().reset_index()

# Renaming the columns of the new DataFrame
dfcitas.columns = ['NPatente','ncitas']

# Printng the DataFrame
print(dfcitas)

Your help is appreciated here.

Thank you!

Upvotes: 2

Views: 11224

Answers (1)

Kriti Pawar
Kriti Pawar

Reputation: 860

Please check here to write pandas dataframe as parquet

df.to_parquet('df.parquet.gzip',
              compression='gzip') 

Upvotes: 1

Related Questions