我使用动态帧在S3中编写一个镶木地板文件,但如果文件已经存在,我的程序会附加一个新文件而不是替换它.我使用的句子是这样的:
glueContext.write_dynamic_frame.from_options(frame = table,
connection_type = "s3",
connection_options = {"path": output_dir,
"partitionKeys": ["var1","var2"]},
format = "parquet")
Run Code Online (Sandbox Code Playgroud)
有什么东西"mode":"overwrite"可以替换我的镶木地板文件吗?
我正在尝试使用S3中的pyarrow覆盖我的实木复合地板文件。我看过文档记录,但没有发现任何东西。
这是我的代码:
from s3fs.core import S3FileSystem
import pyarrow as pa
import pyarrow.parquet as pq
s3 = S3FileSystem(anon=False)
output_dir = "s3://mybucket/output/my_table"
my_csv = pd.read_csv(file.csv)
my_table = pa.Table.from_pandas(my_csv , preserve_index=False)
pq.write_to_dataset(my_table,
output_dir,
filesystem=s3,
use_dictionary=True,
compression='snappy')
Run Code Online (Sandbox Code Playgroud)
mode = "overwrite"write_to_dataset函数中是否有类似option的选项?
我有这个多索引数据框:
df=pd.DataFrame(np.zeros((3,6)))
df.columns=pd.MultiIndex.from_arrays([['a','a','b','b','c','c'],[1,2,1,2,1,2]])
df['a']=10
df['b']=20
df['c']=40
print(df)
Out[10]:
a b c
1 2 1 2 1 2
0 10 10 20 20 40 40
1 10 10 20 20 40 40
2 10 10 20 20 40 40
Run Code Online (Sandbox Code Playgroud)
我想得到这个:
Out[10]:
names 1 2
0 a 10 10
1 a 10 10
2 a 10 10
0 b 20 20
1 b 20 20
2 b 20 20
0 c 40 40
1 c 40 40
2 c 40 40
Run Code Online (Sandbox Code Playgroud)
我知道我可以将数据框中的每一列第一级分开,然后进行追加,但我正在寻找更好的方法来做到这一点。 …
我有一个 SAS 表,我尝试用 Spark 读取它。我尝试使用这个https://github.com/saurfang/spark-sas7bdat,但我无法让它工作。
这是代码:
from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)
df = sqlContext.read.format("com.github.saurfang.sas.spark").load("my_table.sas7bdat")
Run Code Online (Sandbox Code Playgroud)
它返回此错误:
Py4JJavaError: An error occurred while calling o878.load.
: java.lang.ClassNotFoundException: Failed to find data source: com.github.saurfang.sas.spark. Please find packages at http://spark.apache.org/third-party-projects.html
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:635)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:190)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.github.saurfang.sas.spark.DefaultSource
at java.net.URLClassLoader.findClass(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud)