4 examples of 'pandas copy dataframe' in Python

Every line of 'pandas copy dataframe' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
993def hpat_pandas_series_copy_impl(self, deep=True):
994 if deep:
995 return pandas.Series(self._data.copy(), index=self._index.copy())
996 else:
997 return pandas.Series(self._data, index=self._index.copy())
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

206def to_pandas(self):
207 return self.dataframe
136def copy_column(self, to, fro):
137 """Copy column data
138
139 Args:
140 fro (str): column name to copy data from
141 to (str): column name to copy to
142 """
143 logging.debug("copying {} to {}".format(fro, to))
144 self.df[to] = self.df[fro]
151def postgresql_copy_from(df, name, con ):
152 # append data into existing postgresql table using COPY
153
154 # 1. convert df to csv no header
155 output = cStringIO.StringIO()
156
157 # deal with datetime64 to_csv() bug
158 have_datetime64 = False
159 dtypes = df.dtypes
160 for i, k in enumerate(dtypes.index):
161 dt = dtypes[k]
162 print 'dtype', dt, dt.itemsize
163 if str(dt.type)=="<type 'numpy.datetime64'>":
164 have_datetime64 = True
165
166 if have_datetime64:
167 d2=df.copy()
168 for i, k in enumerate(dtypes.index):
169 dt = dtypes[k]
170 if str(dt.type)=="<type 'numpy.datetime64'>":
171 d2[k] = [ v.to_pydatetime() for v in d2[k] ]
172 #convert datetime64 to datetime
173 #ddt= [v.to_pydatetime() for v in dd] #convert datetime64 to datetime
174 d2.to_csv(output, sep='\t', header=False, index=False)
175 else:
176 df.to_csv(output, sep='\t', header=False, index=False)
177 output.seek(0)
178 contents = output.getvalue()
179 print 'contents\n', contents
180
181 # 2. copy from
182 cur = con.cursor()
183 cur.copy_from(output, name)
184 con.commit()
185 cur.close()
186 return

Related snippets